The Udacity ES6 training has a question about overriding a base class constructor. I've got a solution but Udacity doesn't let me get away with it.
The assignment is: Create a Bicycle subclass that extends the Vehicle class. The Bicycle subclass should override Vehicle's constructor function by changing the default values for wheels from 4 to 2 and horn from 'beep beep' to 'honk honk'.
class Vehicle {
constructor(color = 'blue', wheels = 4, horn = 'beep beep') {
this.color = color;
this.wheels = wheels;
this.horn = horn;
}
honkHorn() {
console.log(this.horn);
}
}
// your code here
/* tests
const myVehicle = new Vehicle();
myVehicle.honkHorn(); // beep beep
const myBike = new Bicycle();
myBike.honkHorn(); // honk honk
*/
The solution that I come up with is:
class Bicycle extends Vehicle {
constructor(wheels, horn){
super(wheels, horn)
this.wheels = 2
this.horn = "honk honk"
}
honkHorn(){
super.honkHorn()
}
}
But that is not good enough And I do not understand why that is. The feedback I got is:
Your Bicycles constructor doesn't set default values for color, wheels, and horn
constructor(wheels = 2, horn = 'tring tring')