+ 1
Beginner... Can anybody please tell my why this isn't working?
3 Answers
+ 4
Change to this
var hours = 0;
var mins = 0;
var secs = 0;
function clock()
{
document.body.innerHTML = hours+":"+mins+":"+secs;
++secs;
}
+ 3
Thanks Calvin!
+ 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