GreatFrontEnd

Counter Solution

Languages
HTMLJS
Difficulty
Easy
Recommended Duration
5 mins

This is a short question which only requires one state variable, which is the number of times the button has been clicked (count). Attach a 'click' event listener to the <button> and each time it is clicked, increment the count value and update the text with that value.

Since only the count needs to change, we can use a <span> to target the count text and update its textContent whenever a click event is fired.

Test Cases

  • Click on the counter to increment the count value by one.

Companies

Premium FeaturePurchase premium to see companies which ask this question.
View plans

Try these questions next


Similar Questions

You are viewing the solution. Any changes made to the code are not saved.

Loading...