Published
Edited
Sep 28, 2018
6 stars
Insert cell
Insert cell
class Bicycle {
// ###### CONSTRUCTOR ########
// runs when the class is instantiated
constructor(owner, color) {
this.cadence = 0;
this.speed = 0;
this.gear = 1;
this.owner = owner || "no name";
this.color = color || "unknown color";
}
// ##########################

// ####### METHODS ##########
changeCadence(newValue) {
this.cadence = newValue;
}

changeGear(newValue) {
this.gear = newValue;
}

speedUp(increment) {
this.speed = this.speed + increment;
}

applyBrakes(decrement) {
this.speed = this.speed - decrement;
}

printStatus() {
return("Cadence:"+this.cadence+"\n" +
"Speed:" + this.speed + "\n" +
"Gear:" + this.gear + "\n" +
"Color:" + this.color + "\n" +
"Name Tag:" + this.owner + "\n" )
}
// ###########################
}
Insert cell
Insert cell
mikesBike = new Bicycle("Mike", "red")
Insert cell
billsBike = new Bicycle("Bill", "blue")
Insert cell
Insert cell
mikesBike.printStatus()
Insert cell
Insert cell
Insert cell
class CamouflageBike extends Bicycle {
constructor(owner) {
// call parent constructor
super(owner, "green")
// new instance variables
this.visible = true;
}
// new method
camouflage() {
this.visible = !this.visible;
}
}
Insert cell
myStealthyBoi = new CamouflageBike("Rambo")
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more