0

addEventListener null

https://code.sololearn.com/WGBp2ElP6oy9/?ref=app pls help?? what is the problem in it??

23rd Jun 2021, 10:49 AM
aslam Sidheeq
5 Respuestas
+ 3
That's an error on your side. To fix that, on line 24, replace random() with Math.random() On line 8, there exists another error: you forgot to type span class="color", instead, you wrote span="color" You also forgot to close the span tag. After fixing these bugs your code will work perfectly. Cheers👍
23rd Jun 2021, 12:09 PM
Isaac Fernandes
Isaac Fernandes - avatar
+ 3
aslam Sidheeq, To fix this: Cut and paste your code from your javascript tab into your html tag between script tags. This error is a sololearn code playground bug. Not your mistake. It doesn't allow you to use event listeners.
23rd Jun 2021, 11:57 AM
Isaac Fernandes
Isaac Fernandes - avatar
+ 1
great mahn😍👍thank you
23rd Jun 2021, 12:13 PM
aslam Sidheeq
0
Then its showing "random is not defined"
23rd Jun 2021, 11:58 AM
aslam Sidheeq
0
"cut and paste your code from your javascript tab into your html tag between script tags" is a dirty fix ^^ you better have to learn what occurs when using the js tab: on web site, the js tab is inserted at end of html as an IIFE (Immediatly Invocked Function Execution), wich makes all you define inside not reachable from outside (global scope)... you must "export" what you have to be called from global scope into it by using window object... on app' (at least android) the js tab is inserted inside head section (without isolating code from global scope), meaning that DOM is not ready to be accessed (body part) at time of execution... the correct way to handle all that different cases, is to wrap your js tab code into an onload event listener function handler, "exporting" explicitly vars / functions wich need to be available in global scope: onload = () => { window.global_var = 42; window.global_func = global_func; // code function global_func() { // function body } };
23rd Jun 2021, 7:54 PM
visph
visph - avatar