Add a deposit method that increases the balance and returns it.
Acceptance criteria
- 1.#out should show 150.
JavaScript Tutorial · JavaScript Classes
These 10 tasks go with the JavaScript Class Methods chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Class methods are functions shared by every instance of the class.” .
1.Write a method with a parameterexercise · easy · 10 min
Add a deposit method that increases the balance and returns it.
Passes when: #out should show 150.
2.Call another methodexercise · easy · 10 min · practice plan
Have total call tax through this.
Passes when: #out should show 120.
3.Show methods are sharedexercise · easy · 10 min · practice plan
Report whether two instances share the same method function.
Passes when: #out should show true.
4.Chain method callsexercise · easy · 10 min · practice plan
Return this from up so the calls can be chained.
Passes when: #out should show 3.
5.Bind a detached methodexercise · medium · 10 min · practice plan
Pull the method out and bind it so it still works.
Passes when: #out should show Hello Ada.
6.Fix the method with no returnbug fix · easy · 8 min
The method works out the answer but never gives it back.
Passes when: #out should show 150.
7.Fix the sibling method called without thisbug fix · easy · 8 min · practice plan
A method must be reached through this.
Passes when: #out should show 120.
8.Fix the chain that returns a valuebug fix · easy · 8 min · practice plan
up must return this for chaining to work.
Passes when: #out should show 3.
9.Fix the detached methodbug fix · easy · 8 min · practice plan
Taking a method out of its object loses this.
Passes when: #out should show Hello Ada.
10.Fix the method defined in the constructorbug fix · easy · 8 min · practice plan
A method belongs in the class body so instances share it.
Passes when: #out should show true.
Between them these tasks cover Methods, this and Chaining.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.