Skip to main content

JavaScript Object Methods — exercises and bug fixes

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

    easy10 min

    Add a greet method that uses the name on the object.

  2. 2

    Calculate from properties

    easy10 min

    Write an area method that multiplies the width and height.

  3. 3

    Take a parameter

    easy10 min

    Write a deposit method that adds to the balance and returns it.

  4. 4

    Call another method

    easy10 min

    Have one method call another through this.

  5. 5

    Add a method later

    medium10 min

    Add a method to an existing object and call it.

Find the bug(5)

  1. 1

    Fix the missing this

    easy8 min

    Without this the method cannot see its own property.

  2. 2

    Fix the arrow used as a method

    easy8 min

    An arrow function has no this of its own, so the name is lost.

  3. 3

    Fix the method not called

    easy8 min

    Without brackets the function itself is shown, not its result.

  4. 4

    Fix the method with no return

    easy8 min

    The method works out the answer but never gives it back.

  5. 5

    Fix the balance never stored

    easy8 min

    The method returns the new total but does not save it.

Ready to write the code?

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

Open the workspace