+ 1

How come my javascript is not working?

I am trying to make a simple clock and am trying to make it so if it is between 7am and 7pm it will display a background image but it doesnt seem to work. I copied the code over from my desktop and sololearn is giving it an error of null on line 11 for some reason. I do not get this error on my desktop. The code in question is currently commented out. https://code.sololearn.com/WE6mYUaREHd6/?ref=app

11th Jun 2019, 6:47 PM
Ryan Lusby
Ryan Lusby - avatar
5 odpowiedzi
+ 2
I think you have issue on copying the text to code playground, it seems there are extra hidden codes in html. I retype your html clock-time id, it can work then. https://code.sololearn.com/W682MhvMdCqF/?ref=app
12th Jun 2019, 1:26 AM
Calviղ
Calviղ - avatar
+ 1
Calviղ i dont quite understand what you did. It looks like you added a second div with the clock-time id and also changed its positioning. It still doesnt seem to display like it does on my laptop though but it is displaying a time now lol. I'm trying to figure out why I'm unable to get the background to change using javascript though. Could you look at that specifically to see how i am going about it and let me know what I'm doing wrong?
12th Jun 2019, 3:35 AM
Ryan Lusby
Ryan Lusby - avatar
+ 1
your script is running before the divs populate so it cant find it
12th Jun 2019, 3:59 AM
Jason Kennedy
+ 1
uh..yes..the problem IS that the script is running first DUE to how it was copy and pasted. go ahead and delete the onload..same error...because its not doing anything
12th Jun 2019, 7:57 AM
Jason Kennedy
0
Ryan Lusby You must be copying the codes from somewhere else. The codes have the hidden character which making your html not working. Please type the html codes on code playground and laptop, you would see the codes is working as you want. Jason Kennedy the code is run after onload. So the issue you mentioned does not exist.
12th Jun 2019, 4:07 AM
Calviղ
Calviղ - avatar