Skip to content
Merged
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
1 change: 0 additions & 1 deletion bike-shop/src/stage3-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Tire.prototype.isFlat = function () {

Tire.prototype.puncture = function () {
this._isFlat = true
//this.tires[0]._isFlat = true
}


Expand Down
59 changes: 57 additions & 2 deletions bike-shop/src/stage4-inheritance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,69 @@ class Frame {
}

class Tire {
// your code here

}

class Bike {
// your code here
constructor() {
this.tires = [new Tire, new Tire]
this.frame = new Frame
this.brakes = {
back : true,
front : true
}
this.rings = [3, 7]
}
}

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

class BMXBike extends Bike {
constructor() {
super();
this.brakes.front = false;
this.tires[0].diameter = 20;
this.tires[1].diameter = 20;
}
}

class RacingBike extends Bike {
constructor(val) {
super(val);
this.tires[0].type = 'road';
this.tires[1].type = 'road';
this.frame.style = 'racing';
//work on this below
this.rings[0] = 3;
this.rings[1] = 10;
}
gearSpeeds(){
return this.rings[0] * this.rings[1];
}
}



//let mountainBike = new MountainBike()
//let racingBike = new RacingBike()



module.exports = {
Bike: Bike,
MountainBike: MountainBike,
BMXBike: BMXBike,
RacingBike: RacingBike
// you'll need to export new classes here
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<title></title>
</head>
<body>
<script src="bike-shop/src/stage3-methods.js" charset="UTF-8"></script>
<script src="bike-shop/src/stage4-inheritance.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions jsinfo/errorCreatingAnInstance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Here’s the code with Rabbit extending Animal.

Unfortunately, Rabbit objects can’t be created.
What’s wrong? Fix it.
*/
class Animal {

constructor(name) {
this.name = name;
}

}

class Rabbit extends Animal {
constructor(name) {
//need to add a supper function to allow inheritance
super(name)
//now with the super()
//this.name = name;
this.created = Date.now();
}
}

let rabbit = new Rabbit("White Rabbit"); // Error: this is not defined
alert(rabbit.name);
57 changes: 57 additions & 0 deletions jsinfo/extendClock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Clock {
// ({ ... }) allows the item to be passed in as a object literal
constructor({template}){
this._template = template;
}
// prototype not allowed in classes. bound to the class function
_render() {
let date = new Date();

let hours = date.getHours()
if (hours < 10) hours = '0' + hours;

let mins = date.getMinutes();
if (mins < 10) min = '0' + mins;

let secs = date.getSeconds();
if (secs < 10) secs = '0' + secs;

let output = this._template
.replace('h', hours)
.replace('m', mins)
.replace('s', secs);

console.log(output);
}

//clock.stop() will stop the clock
stop() {
clearInterval(this._timer);
console.log("clocked stopped");
};

//clock.start() would then restart the clock
start() {
this._render();
//setInterval(function, milliseconds, param1, param2, ...)
this._timer = setInterval(() => this._render(), this._precision);
}
}

// pass inheritence from Clock to ExtendedClock
class ExtendedClock extends Clock {

constructor(val) {
//allows for the inheritence to be manipulated
super(val)
//set the variable
let {precision=1000} = val;
this._precision = precision;
}
}

let clock = new ExtendedClock({
template: 'h:m:s',
precision: 1000
});
clock.start();
4 changes: 2 additions & 2 deletions jsinfo/rewritePrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ Clock.prototype.stop = function() {
};

Clock.prototype.start = function() {
this.render();
this.timer = setInterval(() =>this.render(), 1000);
this._render();
this.timer = setInterval(() =>this._render(), 1000);
};


Expand Down
1 change: 1 addition & 0 deletions jsinfo/rewriteToClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let clock = new Clock({template: 'h:m:s'});
class Clock {
// ({ ... }) allows the item to be passed in as a object literal
constructor({template}){
//wanted to
console.log(typeof({template}));
this._template = template;
}
Expand Down