Given these two classes, what properties and/or methods would a parent class of Pet have? What would need to modified/removed/added on our classes of Dog
and Cat
for them to inherit from Pet
?
class Dog {
constructor(name, breed, tricksArray) {
this.name = name;
this.breed = breed;
this.tricks = tricksArray;
}
speak() {
console.log('Noise');
}
doTrick(trick) {
if ( this.tricks.includes(trick) ) {
return `${this.name} does a trick: ${trick}!`
} else {
return `${this.name} doesn't know how to ${trick}!`
}
}
}
// Cat.js
class Cat {
constructor(name, breed, faveTreat) {
this.name = name;
this.breed = breed;
this.faveTreat = faveTreat;
}
speak() {
console.log('Noise');
}
feedTreat(treat) {
if ( this.faveTreat == treat ) {
return `${this.name} eats a treat: ${treat}`
} else {
return `${this.name} casually sniffs the ${treat} and then ignores it.`
}
}
}