Make Dog extend Animal and use the inherited method.
Acceptance criteria
- 1.#out should show some sound.
JavaScript Tutorial · JavaScript Classes
These 10 tasks go with the JavaScript Class Inheritance chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “extends creates a class that inherits everything from another class.” .
1.Extend a classexercise · easy · 10 min
Make Dog extend Animal and use the inherited method.
Passes when: #out should show some sound.
2.Add to the parentexercise · easy · 10 min · practice plan
Give the child its own method as well as the inherited one.
Passes when: #out should show eating and fetching.
3.Show the parent cannot see the childexercise · easy · 10 min · practice plan
Report the type of a child method read from a parent instance.
Passes when: #out should show undefined.
4.Inherit a static methodexercise · easy · 10 min · practice plan
Call a parent static method through the child class.
Passes when: #out should show a base thing.
5.Use composition insteadexercise · medium · 10 min · practice plan
Give the car an engine rather than extending it.
Passes when: #out should show engine started.
6.Fix the missing extendsbug fix · easy · 8 min
Without extends the child inherits nothing.
Passes when: #out should show some sound.
7.Fix the inheritance the wrong way roundbug fix · easy · 8 min · practice plan
The dog should extend the animal, not the other way about.
Passes when: #out should show eating and fetching.
8.Fix the method copied instead of inheritedbug fix · easy · 8 min · practice plan
The child should inherit the method rather than repeat it.
Passes when: #out should show shared once.
9.Fix the inheritance used for a has-abug fix · easy · 8 min · practice plan
A car has an engine; it is not a kind of engine.
Passes when: #out should show car has an engine.
10.Fix extending two classesbug fix · easy · 8 min · practice plan
A class can extend only one other class.
Passes when: #out should show breathing.
Between them these tasks cover extends, Inherited methods and Composition.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.