+ 1
Why is this javascript clock acting wierd?
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
+ 3
//Try this
setInterval(()=>{
d=new Date();
document.body.innerHTML=d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();},1);
https://code.sololearn.com/W1LHd1ghb4pB/?ref=app
+ 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);
+ 2
This is why I love this community 😭😭😭... people don't hesitate to help.... Thanks.
0
why do you think so?