Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the base repository for the [Init 2: OOP Practice with Bike Shop](http:/
1. Install Node.js and npm
<br>Follow the instructions in this [Treehouse blog](http://blog.teamtreehouse.com/install-node-js-npm-mac) to install [Node.js](https://nodejs.org/en/) and [npm](https://www.npmjs.com/) using Homebrew on your Mac.
1. Do your work in the subdirectories (`bike-shop/`, `jsinfo/`, `music-player/`)
<br>Be sure to read the `README.md` files in the subdiretories as well.
<br>Be sure to read the `README.md` files in the subdirectories as well.

## Resources

Expand Down
21 changes: 21 additions & 0 deletions bike-shop/src/stage1-literals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
const myBike = {
// your code here
name: "Roadster",
price: 199.99,
frame: {
height: 55,
color: "blue",
style: "cruiser"
},

brakes: {
front: false,
back: true
},

tires: {
diameter: 22,
type: 'fat'
},
rings: [2,5],

}



module.exports = myBike
29 changes: 23 additions & 6 deletions bike-shop/src/stage2-constructors.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
function Bike() {
// your code here
function Bike(name, price) {
this.name = name;
this.price = price;
this.rings = [3,7];
this.brakes = {
front: true,
back: true
}
this.frame = new Frame();
this.tires = [];
this.tires[0] = new Tire();
this.tires[1] = new Tire();

function Frame() {
// your code here
}

function Tire() {
// your code here

function Frame(color, size, style) {
this.color = color || "black";
this.size = size || 55;
this.style = style || "street";

}


function Tire(diameter, type) {
this.diameter = diameter || 22,
this.type = type || "street"
}

module.exports = {
Expand Down
44 changes: 40 additions & 4 deletions bike-shop/src/stage3-methods.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
function Bike() {
// your code here
}
this.isMoving = function(){
return false;
};
this.tires = [new Tire(), new Tire()]
this.pedal = function (){
if (this.tires[0].isFlat() || this.tires[1].isFlat()) {
throw "Can't pedal with a flat tire"
}

this.isMoving = function (){
return true;
}
}
this.brake = function(){
this.isMoving = function(){
return false;
}
}
this.gearSpeeds = function(){
}
this.rings = [3,7];
this.gearSpeeds = function(){
return this.rings[0] *this.rings[1]
}
}


function Frame() {
// your code here
}

function Tire() {
// your code here
this.isFlat = function(){
return false;
}
this.puncture = function(){
this.isFlat = function(){
return true;
}
};
this.repair = function(){
this.isFlat = function(){
return false;
};
}
}

module.exports = {
Bike: Bike,
Frame: Frame,
Tire: Tire
}
};
50 changes: 46 additions & 4 deletions bike-shop/src/stage4-inheritance.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
class Frame {
// your code here
constructor () {
this.style = "default";
}
}

class Tire {
// your code here
constructor (){
this.type = "default";
this.diameter = 20;

}
}

class Bike {
constructor (){
this.frame = new Frame;
this.tires = [new Tire(), new Tire()];
this.brakes = new Brakes;
}
}

class MountainBike extends Bike {
constructor () { super();
this.frame.style = "mountain";
this.tires[0].type = "dirt";
this.tires[1].type = "dirt";
this.shocks = 20;
}

adjustShocks (num){
this.shocks = num;
}
}

class BMXBike extends Bike {
}

class RacingBike extends Bike {
// this.style = "racing"
// this.type = "road"

}

class Bike {
// your code here
class Brakes {
constructor(){
this.front = false;
this.back = true;
}
}

module.exports = {
Bike: Bike,
MountainBike: MountainBike,
BMXBike: BMXBike,
RacingBike: RacingBike,
// you'll need to export new classes here
}
1 change: 1 addition & 0 deletions bike-shop/test/stage3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('Bike', () => {

test('can tell the number of speeds with #gearSpeeds()', () => {
const myBike = new Bike()
myBike.rings = [3,7]
expect(myBike.gearSpeeds()).toBe(21)
myBike.rings = [2,5]
expect(myBike.gearSpeeds()).toBe(10)
Expand Down
11 changes: 11 additions & 0 deletions jsinfo/Accumulator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var Accumulator = function(startingValue){
this.value = startingValue;

this.read = function (){
this.value += +prompt("enter a number:", 0);
};
}



let accumulator = new Accumulator()
12 changes: 12 additions & 0 deletions jsinfo/calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let calculator = {
sum () {
return this.a + this.b;
},
mul () {
return this.a * this.b;
},
read () {
this.a = +prompt('first number', 0);
this.b = +prompt('second number', 0);
}
}
17 changes: 17 additions & 0 deletions jsinfo/chaining.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let ladder = {
step: 0,
up() {
this.step++;
return this;
},

down() {
this.step--;
return this;
},

showStep: function(){ //current step
alert( this.step);
return this;
}
}
33 changes: 33 additions & 0 deletions jsinfo/extendableCalculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//method calculate(str) takes a str and returns result
//make "+" = +
//make "-" = -
//add operator constructor function
//func will = calculate(str)^^

function calculate(){
this.calculate = function(str){

var split = str.split(" ")
var a = parseInt(split[0]); //num
var b = parseInt(split[2]); //num
let operator = split[1] // op
}

}
//method obj

//each operator stores in an array


};
this.addMethod = function(name, func)
// function addOperator(name, func){
// this.name = name;
// this.func = func; //**
//
// }
//calculator.add methods of operations = function created, actual function)
this.addMethod = function(name, func) {
methods.name = func;// what does this mean?
};
//
9 changes: 9 additions & 0 deletions jsinfo/helloObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let user = {}
user.name = "John"
user.surname = "Smith"
user.name = "Pete"
//Object.assign (user, {name: "Pete", isAdmin: true})
delete user.name
//Object.assign (user, {name: "Pete", isAdmin: true})

console.log(user)
17 changes: 17 additions & 0 deletions jsinfo/multNumericBy2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let fee = { adult: 5, child: 10, title: "Entrance Fee"}



function multiplyNumeric(obj) {
for (let key in obj){
if (typeof obj[key] == 'number'){
obj[key] *= 2
}
}
}
//if value === num
//mult value x


console.log(multiplyNumeric(fee))
//github
23 changes: 23 additions & 0 deletions jsinfo/newCalculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//calculator is a constructor function w 3 methods

//this.read is a function/prompts for values store as obj properties
//sum a + b
//mul a * b

function calculator(){ //calculator org func
this.read = function (){
this.a = +prompt("enter first number:", 0) //num 1
this.b = +prompt("enter second number:", 0) //num 2
},
this.sum = function (){ //calculator sum obj/func/prop
return this.a + this.b; //return num a + b
},
this.mul = function (){
return this.a * this.b;
}

}
let calculator = new Calculator;

alert( "Sum =" + calculator.sum() );
alert( "Mul =" + calculator.mul() );
21 changes: 21 additions & 0 deletions jsinfo/searching.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


let head = {
glasses: 1
};

let table = {
pen: 3
_proto_: head
};

let bed = {
sheet: 1,
pillow: 2
_proto_: table
};

let pockets = {
money: 2000
_proto_: bed
};
12 changes: 11 additions & 1 deletion music-player/album.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
// Your code here

const Artist = require('/.artist');
class Album {
constructor (title, songcount, artist){
this.title = title;
this.songcount = songcount;
this.artist = artist;
}
}

module.exports = Album
12 changes: 11 additions & 1 deletion music-player/artist.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
// Your code here
class Artist {
constructor(name, bandmembers, genre){
this.name = name;
this.bandmembers = bandmembers;
this.genre = genre;
}
}

let littleDragon = new Artist ("Little Dragon", ["Yukimi Nagano", "Erik Bodin", "Hakan Wirenstrand", "Frederik Wallin"], "Indie");

console.log(littleDragon.artist)
Loading