Hw6_ipynb_2_
%%js
class Appliance {
constructor(name) {
this.name = name;
}
name() {
return "I am a " + this.constructor.name + " and my model is " + this.name;
}
}
// Below this name the class and cause it to inherit from the Appliance class
class Computer extends Appliance{
constructor(name) {
super(name);
}
}
let newConputer = new Computer("Computer");
console.log(newComputer.name())
popcorn 2
Create child classes of the product class with items, and add parameters depending on what it is. An example is provided of a bagel.
%%js
class organ{
constructor(price,size,taxRate) {
this.price = price;
this.size = size;
this.taxRate = taxRate;
}
getPrice() {
return this.price + this.taxRate * this.price;
}
product(){
const className = this.constructor.name.toLowerCase();
return "You are ordering a " + className + " with a price of " + this.getPrice() + " dollars, a size of " + this.size;
}
}
class organ extends Product{
constructor(price, size, taxRate, weight) {
super(price, size, taxRate);
this.flavor = flavor;
}
getPrice(){
return super.getPrice() * this.size;
}
product(){
return super.product() + " and a flavor of " + this.flavor;
}
}
var sesameBagel = new Bagel(1.5, 2, 0.07, "sesame");
console.log(sesameBagel.product());