Enjoy 20% off all plans by following us on social media. Check out other promotions!

Counter Solution

Author
Ex-Meta Staff Engineer
Languages
HTMLJS

Solution

This is a short question which only requires one state variable, which is the number of times the button has been clicked (count).

Declare count as an instance variable and create a method increment that increments the count. This method is bound to the <button>'s click action and will be called when the <button> is clicked.

Test Cases

  • Click on the counter to increment the count value by one.
  • Click multiple times and check that the count value increases on each click.