1// Do NOT use the `class` keyword anywhere.
2// Implement Animal and Dog using constructor functions + prototype chain.
3
4function Animal(name, sound) {
5 // set this.name and this.sound
6}
7
8Animal.prototype.speak = function() {
9 // return `${this.name} says ${this.sound}`
10};
11
12function Dog(name) {
13 // Call Animal constructor (like super(name, "Woof"))
14}
15
16// Set up Dog's prototype chain to inherit from Animal
17// Fix the constructor reference
18
19Dog.prototype.fetch = function() {
20 return `${this.name} fetches the ball!`;
21};
22
23// Test runner — do not modify
24function solve(mode, ...args) {
25 if (mode === "speak") {
26 const a = new Animal(args[0], args[1]);
27 return a.speak();
28 }
29 if (mode === "dog-speak") {
30 const d = new Dog(args[0]);
31 return d.speak();
32 }
33 if (mode === "dog-fetch") {
34 const d = new Dog(args[0]);
35 return d.fetch();
36 }
37 if (mode === "instanceof") {
38 const d = new Dog(args[0]);
39 return d instanceof Animal;
40 }