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?

20th Jun 2019, 4:18 PM
Xle6yWek
Xle6yWek - avatar
4 Respuestas
+ 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.
20th Jun 2019, 4:47 PM
Russ
Russ - avatar
+ 4
In your code, printall is a local variable which can be accessed only inside printTime function. https://code.sololearn.com/WGLn8xDKUE9s/?ref=app
20th Jun 2019, 4:22 PM
Ayan Fox
Ayan Fox - avatar
+ 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. 😄👍
20th Jun 2019, 4:31 PM
Ayan Fox
Ayan Fox - avatar
+ 1
how can i fix it?
20th Jun 2019, 4:28 PM
Xle6yWek
Xle6yWek - avatar