Skip to main content

JavaScript Object Constructors — exercises and bug fixes

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

    easy10 min

    Write a Person constructor and build one with the name Ada.

  2. 2

    Store two properties

    easy10 min

    Build a Car with a brand and year and show both.

  3. 3

    Build two separate objects

    easy10 min

    Build two cars and show that they hold different brands.

  4. 4

    Add a prototype method

    easy10 min

    Put a greet method on the prototype and call it.

  5. 5

    Use a class instead

    medium10 min

    Write the same thing as a class and call its method.

Find the bug(5)

  1. 1

    Fix the missing new keyword

    easy8 min

    Without new the constructor builds nothing and returns undefined.

  2. 2

    Fix the parameter never stored

    easy8 min

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

  3. 3

    Fix the shared object

    easy8 min

    Returning one fixed object means every car is the same one.

  4. 4

    Fix the method on the wrong place

    easy8 min

    The method was put on the constructor itself, not its prototype.

  5. 5

    Fix the class constructor named wrongly

    easy8 min

    The setup method must be called constructor.

Ready to write the code?

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

Open the workspace