+ 4

Why it doesn't work??

Its a simple clicker game but idk why it doesnt work, pls help (It only works on PC and I want to make it work on mobile too) https://code.sololearn.com/W9P3X1AaDkCh/?ref=app

27th Feb 2023, 10:17 AM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar
11 Respuestas
+ 5
I formatted your code and fixed the events – I am not sure if it actually works as you intended it, but I think the basics work now. I added a little summary in the JS tab. https://code.sololearn.com/Ww13W4uUPGbc/?ref=app
27th Feb 2023, 6:52 PM
Lisa
Lisa - avatar
+ 5
Your code is a little hard to read but I noticed 3 issues: You can only get the html element, e.g. that clicker button, once the body is fully loaded. This means for example, that const clickerButton = document.getElementById('clicker'); should be assigned _after_ the window is loaded. addEventListener() is a method of an html element. So if you want to add the event to the clicker, it should be clickerButton.addEventListener(...) There are some mismatched () and {}. Example in line 13: clickerButton.addEventListener('click"), () => ....) The syntax should be: clickerButton.addEventListener('click', () => {...});
27th Feb 2023, 10:41 AM
Lisa
Lisa - avatar
+ 2
Some interpreters, like mainstream browsers, try hard to get around code errors. The ACID tests measure, in great part, exactly this ability. So a code that fails can work in a browser. I recommend always check your code with validators like the w3c online service: https://validator.w3.org/
27th Feb 2023, 12:15 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Ohhh thanks
27th Feb 2023, 11:18 AM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar
+ 1
I'll try to fix it
27th Feb 2023, 11:19 AM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar
+ 1
The thing is that in PC it works, and when I tried it in mobile, it gave a lot of errors
27th Feb 2023, 11:19 AM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar
+ 1
27th Feb 2023, 12:29 PM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar
+ 1
Lisa I tried to change all the addEventListeners to clickerButton.addEventListener But it doesnt work idk why
27th Feb 2023, 4:55 PM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar
+ 1
I will have a look at it later tonight :)
27th Feb 2023, 5:06 PM
Lisa
Lisa - avatar
+ 1
Thank you so much :)))
27th Feb 2023, 5:12 PM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar
+ 1
Thank you soooooooo much Lisa <3
27th Feb 2023, 8:04 PM
_MinatoGamerYT_
_MinatoGamerYT_ - avatar