Created
July 20, 2019 08:14
-
-
Save elisavetTriant/5843f3bfc4a090a5b71880b2e055bcad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#3 create two classes: an Animal class and a Mamal class. | |
// create a cow that accepts a name, type and color and has a sound method that moo's her name, type and color. | |
class Animal { | |
constructor(name, type, color) { | |
this.name = name; | |
this.type = type; | |
this.color = color; | |
} | |
} | |
class Mamal extends Animal { | |
constructor(name, type, color) { | |
super(name, type, color); | |
} | |
//Good candidate of the Factory Pattern, as not every mamal moooooooooooos their names! | |
sound(){ | |
if (this.type === "cow"){ | |
console.log(`Moooooooooo I'm ${this.name}, a ${this.type}, of color ${this.color}...Mooooooooo....`); | |
} else { | |
console.log(`I'm ${this.name}, a ${this.type}, of color ${this.color}...`); | |
} | |
} | |
} | |
let aCowObject = new Mamal("Linda", "cow", "brown"); | |
aCowObject.sound(); | |
let aCatObject = new Mamal("Fluffy", "cat", "brown"); | |
aCatObject.sound(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment