JavaScript Class Inheritance — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Class Inheritance lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Extend a class
easy10 minMake Dog extend Animal and use the inherited method.
- 2
Add to the parent
easy10 minGive the child its own method as well as the inherited one.
- 3
Show the parent cannot see the child
easy10 minReport the type of a child method read from a parent instance.
- 4
Inherit a static method
easy10 minCall a parent static method through the child class.
- 5
Use composition instead
medium10 minGive the car an engine rather than extending it.
Find the bug(5)
- 1
Fix the missing extends
easy8 minWithout extends the child inherits nothing.
- 2
Fix the inheritance the wrong way round
easy8 minThe dog should extend the animal, not the other way about.
- 3
Fix the method copied instead of inherited
easy8 minThe child should inherit the method rather than repeat it.
- 4
Fix the inheritance used for a has-a
easy8 minA car has an engine; it is not a kind of engine.
- 5
Fix extending two classes
easy8 minA class can extend only one other class.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace