Intermediate

Smart Counter with Watchers

In this challenge, you will build a counter with a allowed range from 0 to 10. Your task is to use a 'watcher' to monitor the counter value. If the user tries to exceed the maximum limit (10) or go below the minimum (0), the counter must be locked at that limit and display a warning message that disappears automatically after 2 seconds.


Objectives

  • Use a watcher to monitor the counter value in real-time.
  • Prevent the counter from being less than 0 or greater than 10.
  • Display a dynamic alert message when limits are reached.
  • Use a timer (setTimeout) to hide the alert message after 2000ms.
Gallery