[Solved] Boolean statement not evaluating in javascript


The problem with your code is that you are trying to work on a piece of code that has already started to operate. In simpler words, the setInterval method will be called every 1000ms, no matter what the value of stopped variable is. If you wish to really stop the log, you can do any of these:

clearInterval()

to completely remove the interval or

       setInterval(function() {
          if (stopped) {
            console.log("The timer is working.");
          }
       }, 1000);

to check if the value of stopped variable has changed or not (after the click) and act accordingly. Choose either of these for your purpose..

solved Boolean statement not evaluating in javascript