Why Does The Time Show Before I Click The Button 🤔💔 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

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

https://code.sololearn.com/WmaNPtau0mtG/?ref=app

8th Nov 2019, 4:09 AM
Siyabonga Samson Lukhele
Siyabonga Samson Lukhele - avatar
6 Answers
+ 10
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>
8th Nov 2019, 4:52 AM
Jaydeep Khatri
Jaydeep Khatri - avatar
+ 6
Remove that setInterval(printTime, 1000); in JS As setInterval is calling the 'printTime' function....
8th Nov 2019, 4:44 AM
Jaydeep Khatri
Jaydeep Khatri - avatar
+ 3
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 🤓
8th Nov 2019, 5:08 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
Come On It's Just Too Boring That Way Cause It Just Stops There 🤔💔
8th Nov 2019, 4:46 AM
Siyabonga Samson Lukhele
Siyabonga Samson Lukhele - avatar
+ 1
Ohh...I Was About To Ask That Question,Thanks For The Tip😳❤️
8th Nov 2019, 6:10 AM
Siyabonga Samson Lukhele
Siyabonga Samson Lukhele - avatar
0
Oh🤔
8th Nov 2019, 4:52 AM
Siyabonga Samson Lukhele
Siyabonga Samson Lukhele - avatar