Pass the name up to the parent with super.
Acceptance criteria
- 1.#out should show Rex the collie.
JavaScript Tutorial · JavaScript Classes
These 10 tasks go with the JavaScript super Keyword 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: “super calls the parent class constructor or one of its methods.” .
1.Call the parent constructorexercise · easy · 10 min
Pass the name up to the parent with super.
Passes when: #out should show Rex the collie.
2.Call a parent methodexercise · easy · 10 min · practice plan
Use super.describe to build on the parent's answer.
Passes when: #out should show an animal that barks.
3.Add a property after superexercise · easy · 10 min · practice plan
Call super first, then set the child's own property.
Passes when: #out should show 4.
4.Rely on the automatic superexercise · easy · 10 min · practice plan
Leave the child constructor out and let the arguments pass through.
Passes when: #out should show Rex.
5.Wrap the parent's workexercise · medium · 10 min · practice plan
Have the child add to what the parent method returns.
Passes when: #out should show [log] at noon: saved.
6.Fix the missing super callbug fix · easy · 8 min
A child constructor must call super before using this.
Passes when: #out should show Rex.
7.Fix this used before superbug fix · easy · 8 min · practice plan
The instance does not exist until super has run.
Passes when: #out should show 4.
8.Fix the parent method rewrittenbug fix · easy · 8 min · practice plan
The child duplicates the parent instead of calling it.
Passes when: #out should show an animal that barks.
9.Fix super called as a methodbug fix · easy · 8 min · practice plan
In a constructor super is called directly, not as super.constructor.
Passes when: #out should show Rex the collie.
10.Fix the wrapped message lostbug fix · easy · 8 min · practice plan
The child should pass its extra text through the parent method.
Passes when: #out should show [log] at noon: saved.
Between them these tasks cover super, Parent constructors and Parent methods.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.