+ 1

Why is this javascript clock acting wierd?

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

25th Aug 2021, 10:30 AM
Sheldon 10110
Sheldon 10110 - avatar
5 Réponses
+ 4
Your function should be together with new Date() object, for get a new time each second: function time(){ var d = new Date(); var hours = d.getHours(); var seconds = 0; var minutes = 0; hours = d.getHours(); seconds = d.getSeconds(); minutes = d.getMinutes(); document.body.innerHTML = hours + ":" + minutes + ":" + seconds; } setInterval(time,1000); https://code.sololearn.com/Wh0An66eJacx/?ref=app
25th Aug 2021, 10:50 AM
JaScript
JaScript - avatar
+ 3
//Try this setInterval(()=>{ d=new Date(); document.body.innerHTML=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();},1); https://code.sololearn.com/W1LHd1ghb4pB/?ref=app
25th Aug 2021, 10:40 AM
SAN
SAN - avatar
+ 2
use those variable inside time function it will work fine 😁 function time(){ var d = new Date(); var hours = d.getHours(); var seconds = 0; var minutes = 0; hours = d.getHours(); seconds = d.getSeconds(); minutes = d.getMinutes(); document.body.innerHTML = hours + ":" + minutes + ":" + seconds; } setInterval(time,1);
25th Aug 2021, 10:47 AM
Pariket Thakur
Pariket Thakur - avatar
+ 2
This is why I love this community 😭😭😭... people don't hesitate to help.... Thanks.
28th Aug 2021, 6:37 PM
Sheldon 10110
Sheldon 10110 - avatar
0
why do you think so?
25th Aug 2021, 10:33 AM
Abhay
Abhay - avatar