Create a simple counter program using JavaScript.




A counter is a very elementary kind of a program. As the name suggests, it is literally used to perform counting (i.e. 0, 1, 2, 3 and so on).

Typically, a counter begins counting at 0 and comes equipped with three buttons: one to increment the count, one to decrement it, and one to reset it back to 0.

Shown below is an example of a counter:

A simple counter program.

In this exercise, you have to create a counter program similar to the one shown above.

Here are the basic rules to abide by:

  • The counter must begin at 0.
  • The increment button must increase the count it by 1.
  • The decrement button must decrease the count by 1.
  • The reset button must reset the count back to 0.
  • The decrement button must NOT decrement the count if it's at 0. In other words, negative counts shouldn't be there in the counter.

Note that this exercise isn't concerned with the design (i.e. the visual design) of the counter. You are only required to get the underlying logic right; the design can be whatever you like.