0
addEventListener null
https://code.sololearn.com/WGBp2ElP6oy9/?ref=app pls help?? what is the problem in it??
5 odpowiedzi
+ 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👍
+ 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.
+ 1
great mahn😍👍thank you
0
Then its showing "random is not defined"
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
}
};