0
Whats a problem?
function printDate() { var d = new Date(); var year = d.getFullYear(); var month = d.getMonth(); var day = d.getDay(); var print = document.write(year+"."+month+"."+day+" "); } // year.month.day function printTime() { var d = new Date(); var hours = d.getHours(); var mins = d.getMinutes(); var secs = d.getSeconds(); var printall = document.write(hours+":"+mins+"."+secs); } // hour:min.sec printDate(print) printTime(printall) setInterval(printTime, 1000); setInterval(printDate, 1000); At the end prints a error at line 17 , why printall doesnt work?
4 Answers
+ 1
You need to make them global by declaring them outside the function definitions. Just put
var print, printall;
at the start of your code.
+ 4
In your code, printall is a local variable which can be accessed only inside printTime function.
https://code.sololearn.com/WGLn8xDKUE9s/?ref=app
+ 4
I don't know đ I'm also learning JavaScript. I can just say that there is no need of those functions. đ
Make a function named clock() and place the whole code inside that. đđ
+ 1
how can i fix it?