I have a small problem.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
12th Jan 2018, 2:11 AM
Reuinte' Howard
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 ^^
12th Jan 2018, 5:15 AM
visph
visph - avatar
+ 6
@Reuinte Howard You are welcome ๐Ÿ˜ƒโค
13th Jan 2018, 6:47 AM
Shehab Amr
Shehab Amr - avatar
+ 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๐Ÿ˜‰
12th Jan 2018, 3:10 AM
Shehab Amr
Shehab Amr - avatar
+ 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?
12th Jan 2018, 3:28 AM
Reuinte' Howard
+ 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!
12th Jan 2018, 2:16 PM
Reuinte' Howard