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
Write a method
easy10 minAdd a greet method that uses the name on the object.
- 2
Calculate from properties
easy10 minWrite an area method that multiplies the width and height.
- 3
Take a parameter
easy10 minWrite a deposit method that adds to the balance and returns it.
- 4
Call another method
easy10 minHave one method call another through this.
- 5
Add a method later
medium10 minAdd a method to an existing object and call it.
Find the bug(5)
- 1
Fix the missing this
easy8 minWithout this the method cannot see its own property.
- 2
Fix the arrow used as a method
easy8 minAn arrow function has no this of its own, so the name is lost.
- 3
Fix the method not called
easy8 minWithout brackets the function itself is shown, not its result.
- 4
Fix the method with no return
easy8 minThe method works out the answer but never gives it back.
- 5
Fix the balance never stored
easy8 minThe 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