0

why i cannot call this function?

function a() { var d = new Date() var a = d.getSeconds() var b = d.getMilliseconds() document.body.innerHTML = `${a}:${b}` } a()

20th Mar 2019, 6:34 AM
Gabriel Junior
Gabriel Junior - avatar
6 ответов
+ 4
5th line is invalid. You need to do this: document.getElementsByTagName("body")[0].innerHTML = "Something"; You also need to wait until the DOM loads the page, so you have to do something like this: window.onload = a; and remove the line with a();
20th Mar 2019, 6:38 AM
Jan Štěch
Jan Štěch - avatar
+ 4
Oh, I see. Fixed.
20th Mar 2019, 6:42 AM
Jan Štěch
Jan Štěch - avatar
+ 3
S Pace Oh, I am not an expert in JS, so I wrote that just to make sure.
20th Mar 2019, 7:17 AM
Jan Štěch
Jan Štěch - avatar
+ 3
I am not an expert @Jan Štěch
20th Mar 2019, 7:22 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
+ 2
Jan Štěch document.body works !
20th Mar 2019, 7:15 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
20th Mar 2019, 7:17 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar