0
Why is this time not running
var ele = document.getElementById("timer"); var timer; var sec = null; let myInterval = (function () { var sec = new Date(); let text = "Minnesota"; let result = text.fontcolor("green"); timer = setInterval(()=> { result = "<span style='color:green'>" + sec.toLocaleTimeString() + "</span>"; ele.innerHTML = result; if (sec == null){sec = time(myInterval, 1000)}; if (sec != null) {clearInterval(sec);} else {document.getElementById("tw").innerHTML = "time is greater than 5";} }, 1000) // each 1 sec } )(); https://code.sololearn.com/WLjHebAQH3nu/?ref=app
5 Answers
+ 2
write specifically what error you are getting
+ 1
so I understood he wants time to change all the time.
+ 1
// Insert this to JS section
function digitalClock() {
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (hours < 10) hours = "0" + hours;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
document.getElementById("id_clock").innerHTML = hours + ":" + minutes + ":" + seconds;
setTimeout("digitalClock()", 1000);
}
<!-- Insert this to HTML section and before and after call function digitalClock(); add tag script -->
<div id="id_clock"></div>
digitalClock();
0
In line 45 you are just re-using the initial time. If you want it to show the current time, you need to get a new date/ current time right before this line.
0
No specific error
I just wanted the code to change seconds automatically
But I have rewritten the code