Okay, I don’t know why this isn’t working. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Okay, I don’t know why this isn’t working.

I am working in JavaScript with the Date Method. I tried some modification, and it said I had a syntax error. For clarity, line 3, var y, is my addition, and I thought I had formatted it exactly like the rest of the code. Why is it not working? function printTime() { var d = new Date(); var y = d.getFullYear(); var hours = d.getHours(); var mins = d.getMinutes(); var secs = d.getSeconds(); document.body.innerHTML = y+":"hours+":"+mins+":"+secs; } setInterval(printTime, 1000);

4th Sep 2019, 1:44 AM
Kimi
2 Answers
+ 1
Try for this, var d = new Date(); document.getElementById("demo").innerHTML = d.getHours(); var d = new Date(); document.getElementById("demo").innerHTML = d.getMinutes(); More details at here, https://www.w3schools.com/js/js_date_methods.asp Good Luck~
4th Sep 2019, 1:49 AM
Uchiha Itachi
Uchiha Itachi - avatar
+ 1
missing a + between ":" and hours for debugging, the syntax error will tell you which line the error occurs. so you should focus on that line, and begin with adding // after y to see if it works, and add the parts one by one slowly to see which part goes wrong.
4th Sep 2019, 2:22 AM
Gordon
Gordon - avatar