Skip to main content

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. 1

    Extend a class

    easy10 min

    Make Dog extend Animal and use the inherited method.

  2. 2

    Add to the parent

    easy10 min

    Give the child its own method as well as the inherited one.

  3. 3

    Show the parent cannot see the child

    easy10 min

    Report the type of a child method read from a parent instance.

  4. 4

    Inherit a static method

    easy10 min

    Call a parent static method through the child class.

  5. 5

    Use composition instead

    medium10 min

    Give the car an engine rather than extending it.

Find the bug(5)

  1. 1

    Fix the missing extends

    easy8 min

    Without extends the child inherits nothing.

  2. 2

    Fix the inheritance the wrong way round

    easy8 min

    The dog should extend the animal, not the other way about.

  3. 3

    Fix the method copied instead of inherited

    easy8 min

    The child should inherit the method rather than repeat it.

  4. 4

    Fix the inheritance used for a has-a

    easy8 min

    A car has an engine; it is not a kind of engine.

  5. 5

    Fix extending two classes

    easy8 min

    A 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