+ 1

Beginner... Can anybody please tell my why this isn't working?

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

1st May 2019, 2:37 PM
Dralecon
Dralecon - avatar
3 Answers
+ 4
Change to this var hours = 0; var mins = 0; var secs = 0; function clock() { document.body.innerHTML = hours+":"+mins+":"+secs; ++secs; }
1st May 2019, 2:56 PM
CalviŐ˛
CalviŐ˛ - avatar
+ 3
Thanks Calvin!
1st May 2019, 2:58 PM
Dralecon
Dralecon - avatar
+ 3
The problem is that the time variables always store 0 within them when the function is called. So just place those variables in the top of the file. Here is the corrected code var hours = 0; var mins = 0; var secs = 0; function timer() { setInterval(clock, 1000); } function clock() { document.body.innerHTML = hours+":"+ +":"+secs++; } I changed some parts of your code and currently it handles seconds only. Use conditionals to handle other variables
1st May 2019, 3:00 PM
Seniru
Seniru - avatar