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);
2 Antworten
+ 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~
+ 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.