I have a peice of code trying to make a list of 25 average numbers 1-25 and they are not showing on the page.
window.onload = function() {
const alt = [];
const avgRate = 3;
for (let i = 0; i = 25; i++) {
alt.push(Math.random()*25)
}
console.log(alt);
document.getElementById('output').innerHTML = alt;
}
<p id="output"></p>
I expected the lists to appear on the page but did not see them Can someone help me with this?
4
Answers
I think maybe it’s supposed to be i != 25 and not i = 25?
I’m pretty sure that i = 25 means the condition for continuation, not the condition for stopping.
the condition in the for loop should run the code 25 times and add elements to it
This is because you create a
i
variable for your for condition and directly affect25
to the value, try to set a stop condition likei < 25
It is causing due to the looping issues you can use
i<=25
and alsoalt.push(Math.floor(Math.random()*25))
to avoid the leading decimal values.