+ 1

... is not defined [solved]

When I run my code on my mobile phone, everything works fine. But when I run it on my laptop, it says "load_level is not defined" when I want to select a level. (The buttons are defined in line 101 in JS.) I've tried getting the HTML elements for the buttons after creating them and then assigning the function to them via "element.onclick = function" and it worked, but then other things such as the array "levels" were "not defined". Apparently, the computer doesn't know the variables and function for some reason. https://code.sololearn.com/WpCApR631liy/?ref=app

19th Mar 2022, 5:05 PM
C. Scheler
C. Scheler - avatar
3 odpowiedzi
+ 3
When running web code via sololearn website any code in the js tab is placed in an IIFE and this is cause of load_level not defined error message. One way to solve this is by using addEventListener on the div that contains the the level divs Line 108 is where I added the extra code https://code.sololearn.com/Wlr7yKM4pPhx
19th Mar 2022, 9:09 PM
ODLNT
ODLNT - avatar
+ 1
ODLNT Thank you! I've added "addEventListener" for the levels and the other buttons. But your solution has one little bug: There's a "-1" missing in line 111 because level 1 has the index 0 in the array. ;)
19th Mar 2022, 10:22 PM
C. Scheler
C. Scheler - avatar
0
FF9900 I've just tried it on my mobile, but then it showed the same error message even though it works on mobile without the IIFE.
19th Mar 2022, 8:53 PM
C. Scheler
C. Scheler - avatar