For this exercise you can use Repl.it or your code editor.
Using the below file hero-factory.js
finish the tasks as specified in the comments in the script.
We included the Syntax Reminder snippets below, to help you with the task:
class Car {
constructor(brand, model) {
// in the constructor we specifiy parameters that will be passed
this.brand = brand; // create property on the new instance
this.model = model;
}
start() {
// create method on the Prototype
console.log(`${this.brand} Engine start`);
}
}
const bmw = new Car("BMW", "750i");
// Car { brand: "BMW", model: "750i" }
bmw.start();
class HybridCar extends Car {
constructor(brand, model, engineType) {
// call class `Car()` via `super()` - which creates properties `brand` and `model` on the new instance
super(brand, model);
this.engineType = engineType; // create an additional property on the new instance
}
// creates a method on the HybridCar prototype
description () {
console.log(`Brand: ${this.brand}. Engine: ${this.engineType}`);
}
// creates a static method that can be called only from class HybridCar
static printClassName() {
console.log("class name is HybridCar");
}
}
const toyotaHybrid = new HybridCar("Toyota", "Prius", "Hybrid");
// HybridCar {brand: "Toyota", model: "Prius", engine: "Hybrid"}
toyotaHybrid.description(); // from the HybridCar.prototype -> bmwHybrid.__proto__
toyotaHybrid.start(); // from the Car.prototype -> bmwHybrid.__proto__.__proto__
Happy Coding! 🚀