Why Does The Time Show Before I Click The Button 🤔💔


11/8/2019 4:09:13 AM

Siyabonga Samson Lukhele

6 Answers

New Answer


That what the code was supposed to do😂 If you need to update with real time, edit the <button> <button onclick="setInterval(printTime, 1000);">Show current time</button>


Remove that setInterval(printTime, 1000); in JS As setInterval is calling the 'printTime' function....


Okay, here is the logic. Create a flag/Boolean variable. Set it to false initially. In if condition check if that variable is true or not, if it is false don't run the setInterval. But when you click the button first time set variable to true and then when it will check for condition it will be true so interval will run and that's how you can make a clock working. Try it 🤓


Come On It's Just Too Boring That Way Cause It Just Stops There 🤔💔


Ohh...I Was About To Ask That Question,Thanks For The Tip😳❤️