Skip to main content

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. 1

    Write a static method

    easy10 min

    Add a static double method and call it on the class.

  2. 2

    Add a static property

    easy10 min

    Store a version on the class and report it.

  3. 3

    Count instances

    easy10 min

    Count how many users have been created.

  4. 4

    Write a factory method

    easy10 min

    Add a static origin method that returns a point at zero.

  5. 5

    Show instances cannot see statics

    medium10 min

    Report the type of a static method read from an instance.

Find the bug(5)

  1. 1

    Fix the static called on an instance

    easy8 min

    A static method belongs to the class, not to instances.

  2. 2

    Fix the missing static keyword

    easy8 min

    Without static the method sits on instances instead of the class.

  3. 3

    Fix the counter stored per instance

    easy8 min

    An instance field gives each object its own count.

  4. 4

    Fix the factory that returns nothing

    easy8 min

    The static method builds a point but never returns it.

  5. 5

    Fix the static reading an instance property

    easy8 min

    A 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