Hi solos, my code is not working and I don't know why | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

22nd Jul 2017, 10:30 PM
Raz
Raz - avatar
4 Answers
+ 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); };
23rd Jul 2017, 12:30 AM
visph
visph - avatar
+ 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(); }
22nd Jul 2017, 10:48 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 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
22nd Jul 2017, 11:00 PM
Raz
Raz - avatar
+ 1
thanks visph, you rock✌
23rd Jul 2017, 7:05 AM
Raz
Raz - avatar