Create a Person class with a name and report it.
Acceptance criteria
- 1.#out should show Ada.
JavaScript Tutorial · JavaScript Classes
These 10 tasks go with the JavaScript Classes 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: “A JavaScript class is a template for creating objects that share the same shape.” .
1.Write a classexercise · easy · 10 min
Create a Person class with a name and report it.
Passes when: #out should show Ada.
2.Build two instancesexercise · easy · 10 min · practice plan
Create two cars with different brands and report both.
Passes when: #out should show Toyota Honda.
3.Add a methodexercise · easy · 10 min · practice plan
Give the class a greet method and call it.
Passes when: #out should show Hello Grace.
4.Show a class is a functionexercise · easy · 10 min · practice plan
Report the typeof a class.
Passes when: #out should show function.
5.Store two propertiesexercise · medium · 10 min · practice plan
Store a name and a role, then report them together.
Passes when: #out should show Ada is a mathematician.
6.Fix the missing newbug fix · easy · 8 min
A class must be called with new.
Passes when: #out should show Ada.
7.Fix the comma between methodsbug fix · easy · 8 min · practice plan
Class methods are not separated by commas.
Passes when: #out should show Hello Ada.
8.Fix the property never storedbug fix · easy · 8 min · practice plan
The constructor takes a name but never puts it on the instance.
Passes when: #out should show Toyota.
9.Fix the shared instancebug fix · easy · 8 min · practice plan
One object is being reused, so both cars have the same brand.
Passes when: #out should show Toyota Honda.
10.Fix the method missing thisbug fix · easy · 8 min · practice plan
Without this the method cannot see the instance property.
Passes when: #out should show Hello Grace.
Between them these tasks cover class syntax, Instances and new.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.