My JS DOM code not working but works when pasted it in the DevTool

I’ve been trying to make some websites (calculator, clock) using HTML, CSS, and JS but every time my JS DOM code doesn’t work. At first, I thought that maybe I didn’t link my JS code properly but after checking, that wasn’t the problem; I even tried to put an alert and it worked. But when I tried to copy and paste my code into the chrome DevTool, it worked. I’ve tried to google it but it seems like it’s not that common. I’d be pleased if anyone can help me solve this problem. Thank you.

Hi, we’ll need some context here to be able to help you, maybe a codebyte, screenshots or error messages, anything that can help us to help you.

Hello, actually there is no error messages and the code work perfectly, it’s just when I open the website in my browser the JS isn’t working; like the clock website, the clock doesn’t work, but when I copy the same code in the DevTool, the clock starts moving. Maybe should I send you the github link of that project?

Sure, why not ! I can take a look. My github username is the same as here.

here is the link

Thanks for your help

1 Like

Well it all seems to be working perfectly fine. I even try it in a sandbox, it is operational. Great clock by the way !

Thanks, bro… :joy: That’s why it’s so confusing, I just can’t find what’s wrong.

1 Like

I’ve tried even using Github pages but still it doesn’t work…

here’s the link

Ok now I see, it’s not working on Github pages. I noticed that you had you had your main.js linked twice, once in your head and one more time before your closing body tag, I’m not sure if you did that on purpose but maybe try remove the link from your head and keep the other one.

waouh… thanks a lot bro… At first my main.js was linked in my HTML head but it didn’t work so I tried to link it at the bottom of my HTML body element to check if it’ll work. Must’ve forgot to remove the head main.js link.
Thanks a lot, now it’s working.

1 Like

That’s great ! No worries, I’ve noticed that some people do link the js file in the head then add defer in their script tag, I thought you went that way and forgot to add it. Anyway keep creating and happy coding !

1 Like