HTML Runner

JavaScript Counter Example

Update a number in response to button presses and keep the display tied to program state.

More
Editor
Live Preview
Console 0 errors · 0 warnings

    Ready

    Find and replace

    How this example works

    A variable holds the current value. Both event handlers call render after changing it, and the output announces the new value.

    Try a change

    Add a Reset button that sets the value to zero. Disable decrement at zero or describe why negative values make sense for your use case.

    Related resources