JavaScript Classes — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Classes 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 class
easy10 minCreate a Person class with a name and report it.
- 2
Build two instances
easy10 minCreate two cars with different brands and report both.
- 3
Add a method
easy10 minGive the class a greet method and call it.
- 4
Show a class is a function
easy10 minReport the typeof a class.
- 5
Store two properties
medium10 minStore a name and a role, then report them together.
Find the bug(5)
- 1
Fix the missing new
easy8 minA class must be called with new.
- 2
Fix the comma between methods
easy8 minClass methods are not separated by commas.
- 3
Fix the property never stored
easy8 minThe constructor takes a name but never puts it on the instance.
- 4
Fix the shared instance
easy8 minOne object is being reused, so both cars have the same brand.
- 5
Fix the method missing this
easy8 minWithout this the method cannot see the instance property.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace