JavaScript Class Methods — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Class 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 with a parameter
easy10 minAdd a deposit method that increases the balance and returns it.
- 2
Call another method
easy10 minHave total call tax through this.
- 3
Show methods are shared
easy10 minReport whether two instances share the same method function.
- 4
Chain method calls
easy10 minReturn this from up so the calls can be chained.
- 5
Bind a detached method
medium10 minPull the method out and bind it so it still works.
Find the bug(5)
- 1
Fix the method with no return
easy8 minThe method works out the answer but never gives it back.
- 2
Fix the sibling method called without this
easy8 minA method must be reached through this.
- 3
Fix the chain that returns a value
easy8 minup must return this for chaining to work.
- 4
Fix the detached method
easy8 minTaking a method out of its object loses this.
- 5
Fix the method defined in the constructor
easy8 minA method belongs in the class body so instances share it.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace