+ 3
Wrap your js code in
window.onload = () => {
// your js code
}
In sololearn code you write in javascript tab is same as you type script at head of html.
For dom element to lead we need this script at bottom of page, before </body>, or to wrap our code inside window.onload
With this we wait for our html elements to load and then we run javascript code