+ 3

Why body? I mean, what it means? (Document.body.innerHTML)

function printTime() { var d = new Date(); var hours = d.getHours(); var mins = d.getMinutes(); var secs = d.getSeconds(); document.body.innerHTML = hours+":"+mins+":"+secs; } setInterval(printTime, 1000);

1st Feb 2017, 7:45 PM
Andrei Iliescu
Andrei Iliescu - avatar
3 Respostas
+ 6
innerHTML sets or gets the content of an element. in your code, the body element will get its content set to the current time periodically every 1 second (1000 miliseconds) also, i would recommend assigning some value to setInterval so you can clear it later (not required in this code, just good practice) var clockInterval=setInterval(printTime,1000); ..... some time later when we want to stop the clock but not the entire program, we'll call clearInterval(clockInterval); which will stop the periodic calling to printTime.
1st Feb 2017, 8:29 PM
Burey
Burey - avatar
+ 2
thanks
1st Feb 2017, 8:55 PM
Andrei Iliescu
Andrei Iliescu - avatar
0
It means the <body> element of the page you write the script for
1st Feb 2017, 8:56 PM
Vasyl Mustyatsa
Vasyl Mustyatsa - avatar