JavaScript Static Members — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Static Members 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 static method
easy10 minAdd a static double method and call it on the class.
- 2
Add a static property
easy10 minStore a version on the class and report it.
- 3
Count instances
easy10 minCount how many users have been created.
- 4
Write a factory method
easy10 minAdd a static origin method that returns a point at zero.
- 5
Show instances cannot see statics
medium10 minReport the type of a static method read from an instance.
Find the bug(5)
- 1
Fix the static called on an instance
easy8 minA static method belongs to the class, not to instances.
- 2
Fix the missing static keyword
easy8 minWithout static the method sits on instances instead of the class.
- 3
Fix the counter stored per instance
easy8 minAn instance field gives each object its own count.
- 4
Fix the factory that returns nothing
easy8 minThe static method builds a point but never returns it.
- 5
Fix the static reading an instance property
easy8 minA static method has no instance, so it cannot read this.name.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace