Add a fullName getter that joins the first and last names.
Acceptance criteria
- 1.#out should show Ada Lovelace.
JavaScript Tutorial · JavaScript Objects
These 10 tasks go with the JavaScript Getters and Setters 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: “JavaScript getters and setters let a method be used like a plain property.” .
1.Write a getterexercise · easy · 10 min
Add a fullName getter that joins the first and last names.
Passes when: #out should show Ada Lovelace.
2.Recalculate on readexercise · easy · 10 min · practice plan
Add an area getter, change the width, and show the new area.
Passes when: #out should show 50.
3.Write a setterexercise · easy · 10 min · practice plan
Add a setter that splits a full name into two properties.
Passes when: #out should show Grace.
4.Validate in a setterexercise · easy · 10 min · practice plan
Reject a negative balance by storing zero instead.
Passes when: #out should show 0.
5.Use a getter in a classexercise · medium · 10 min · practice plan
Add an area getter to a Circle class and show it rounded.
Passes when: #out should show 13.
6.Fix the getter joining the wrong way roundbug fix · easy · 8 min
The names are being joined last first.
Passes when: #out should show Ada Lovelace.
7.Fix the value cached instead of computedbug fix · easy · 8 min · practice plan
A plain property is worked out once and never updates.
Passes when: #out should show 50.
8.Fix the setter with no parameterbug fix · easy · 8 min · practice plan
A setter must accept exactly one value.
Passes when: #out should show Grace.
9.Fix the validation skippedbug fix · easy · 8 min · practice plan
A negative balance is being stored instead of rejected.
Passes when: #out should show balance 0.
10.Fix the missing get keywordbug fix · easy · 8 min · practice plan
Without get the property holds a function rather than its result.
Passes when: #out should show 20.
Between them these tasks cover Getters, Setters and Computed properties.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.