Codetive
Sign In
Coding challenges as of now are only available on desktop
On mobile you can try our quiz
Quiz
We are working hard to bring coding challenges with editor on mobile 💚

Counter

Objective: Build a functional counter using HTML, CSS, and JS/TS/React.

Instructions:

  1. Create a simple counter with the following elements:

    • A display showing the current count.
    • Two buttons: one for incrementing the count and another for decrementing it.
  2. The counter should start at 0 by default.

  3. Clicking the "Increment" button should add 1 to the current count.

  4. Clicking the "Decrement" button should subtract 1 from the current count.

Requirements:

  • The counter must always start at 0 when the page loads.
  • The counter cannot go below 0 (disable the "Decrement" button or handle the logic to prevent negative counts).
  • The count must persist correctly between increments and decrements without refreshing the page.

Hints:

  1. Store the current count in a variable and update it when the buttons are clicked.
  2. Update the displayed count by modifying the inner text of an HTML element (like a <span> or <h1>).
  3. Optionally, you can disable the "Decrement" button when the count is at 0 to prevent negative values.

Bonus:

  • Add a reset button that sets the counter back to 0.
  • Style the buttons and counter display
Browser
Console
Tests
Soon