JavaScript Object Constructors — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Object Constructors 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 constructor
easy10 minWrite a Person constructor and build one with the name Ada.
- 2
Store two properties
easy10 minBuild a Car with a brand and year and show both.
- 3
Build two separate objects
easy10 minBuild two cars and show that they hold different brands.
- 4
Add a prototype method
easy10 minPut a greet method on the prototype and call it.
- 5
Use a class instead
medium10 minWrite the same thing as a class and call its method.
Find the bug(5)
- 1
Fix the missing new keyword
easy8 minWithout new the constructor builds nothing and returns undefined.
- 2
Fix the parameter never stored
easy8 minThe constructor takes a name but never puts it on the object.
- 3
Fix the shared object
easy8 minReturning one fixed object means every car is the same one.
- 4
Fix the method on the wrong place
easy8 minThe method was put on the constructor itself, not its prototype.
- 5
Fix the class constructor named wrongly
easy8 minThe setup method must be called constructor.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace