+ 1
What did I wrong?
I need display numbers from 4 to 400 on the screen but it doesn't work https://code.sololearn.com/WDVW1j0j5JeO/?ref=app
3 Antworten
+ 5
When trying to access the dom elements, we should wait for the window to load.
The code should hence be written in the onload event of window
// display numbers from 5 to 500 on the screen
window.onload = function(){
let out = document.getElementById("out");
let tmp = "";
for (let i=5; i<=500; i++){
tmp = tmp + i + " ";
}
out.innerHTML = tmp ;
}
+ 2
wrap the code inside a function, then add it to body onload listener.
function start(){
//your code
}
<body onload="start()">
+ 1
thanks for helping