Skip to main content

JavaScript Classes — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Classes 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

    Write a class

    easy10 min

    Create a Person class with a name and report it.

  2. 2

    Build two instances

    easy10 min

    Create two cars with different brands and report both.

  3. 3

    Add a method

    easy10 min

    Give the class a greet method and call it.

  4. 4

    Show a class is a function

    easy10 min

    Report the typeof a class.

  5. 5

    Store two properties

    medium10 min

    Store a name and a role, then report them together.

Find the bug(5)

  1. 1

    Fix the missing new

    easy8 min

    A class must be called with new.

  2. 2

    Fix the comma between methods

    easy8 min

    Class methods are not separated by commas.

  3. 3

    Fix the property never stored

    easy8 min

    The constructor takes a name but never puts it on the instance.

  4. 4

    Fix the shared instance

    easy8 min

    One object is being reused, so both cars have the same brand.

  5. 5

    Fix the method missing this

    easy8 min

    Without this the method cannot see the instance property.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace