I have Define a "Animal" prototype object with:
2 properties: name, age and 1 function: sound, I need to create the following objects which are extended from "Animal": Cow, Sheep, Cat (I can use any name and age), then overriding the function "sound" to represent each specific sound of each animal for example:
- Cow has the sound "mooo"
- Sheep has the sound "bee" sheep sound
- Cat has the sound "meow"
I have to use console.log to print the following result:
Name and Age of each type of animal and the sound of each type of animal
I already composed this:
const Animal = {
Cow: {
name: "Peppa",
age: 12,
sound: function cowSound() {
alert("Moo!");
}
},
Sheep: {
name: "Shirley",
age: 7,
sound: function sheepSound() {
alert("Baa!");
}
},
Cat: {
name: "Felipe",
age: 3,
sound: function catSound() {
alert("Meow!");
}
},
};
console.log(JSON.stringify(Animal))
But the result is this: "{"Cow":{"name":"Peppa","age":12},"Sheep":{"name":"Shirley","age":7},"Cat":{"name":"Felipe","age":8}}"
Which is pretty ugly I must admit
How can I display the way I need it with JSON Stringify and see why the sound it's not displaying here, thanks in advance