+ 1
I have a small problem..
5 Answers
+ 3
You define your buttons onclick functions inside the local scope of the onload function, so their are unreachable from outside as the onclick inline attribute which is in the global scope... There are different ways to fix that, most quick would be to add:
window.up = up;
window.left = left;
window.right = right;
window.down = down;
at end of your onload function to "export" the functions used in buttons onclick attributes to the global scope (which is hold by 'window' object).
Another way would be to avoid onclick inline attribute and rather assign dynamically the functions through the use of .addEventListener() method ;)
However, this will fix your "undefined" errors on click, but actually your buttons doesn't product any effects at all ^^
+ 6
@Reuinte Howard You are welcome đâ€
+ 3
alert(
"Hello sololearn communityđ! Recently, I have been trying to create a simple game with a ball moving around, and the gamer controlling the square to avoid the ball, but I have a problem... It is saying that my buttons' functions are undefined.Is there any advice that anyone could give me?đđ Thanks in advance."
);
replace this code in js tab & it will work without any errorđ
best wishes brođ
+ 1
There still seems to be an issue with the button. Could it just be something wrong with my app or is there something that i am looking at wrong?
+ 1
Thank you for the help, both of youđđ I am happy to be in such a community where help is just a message away. As for the buttons' functions not working.... I just thought it was a problem with the function , so i started to play around with itđ
đ
đ
Very silly on my part. Anyways thank you again!