+ 2
Hi solos, my code is not working and I don't know why
I had to post this for the second time cause Q&A is my only hope. My code is printing out some strange error that I don't even understand why. someone please explain to me😰 https://code.sololearn.com/WOLHw7voZFP6/?ref=app
4 Antworten
+ 4
Line 32:
setTimeout(timer(),1000);
If you set parenthesis (rounded brackets () ) after the timer() function name, you call it and set as argument the returned value of its execution, but you need here to pass the function itself... replace it with:
setTimeout(timer,1000);
This will call the timer() function with a delay of 1000ms... maybe do you have forgot to put seconds next:
times.innerHTML = hours + ' : ' + minutes + hours12;
to be replaced with:
times.innerHTML = hours + ' : ' + minutes + ' : ' + seconds + hours12;
Another way to do the infinite delayed loop to refresh time: you can also avoid setTimeout() inside the timer() function, and rather call the setInterval() at first call (inside your initialization in window.onload):
window.onload = function(){
getTrh();
setInterval(timer,1000);
};
+ 9
Without window.onload, your code won't work properly.
...replace from line 37 with this code
//from line 37 add this...
window.onload = function(){
getTrh();
timer();
}
+ 3
thanks buddy, you saved my coding breath.
And can you please run the code again there are some different errors now.
don't see me as lazy in thinking, but its just that I don't understand js well
+ 1
thanks visph, you rock✌