Basic JavaScript - Iterate with JavaScript While Loops

Tell us what’s happening:
Okay no idea what’s wrong with this answer, I even looked at the solution and as far as I know they are identical

Your code so far

// Setup
const myArray = [];

// Only change code below this line
const i = 5;
while(i >= 0) {
myArray.push(i);
i--;
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Iterate with JavaScript While Loops

Link to the challenge:

The console shows “TypeError: “i” is read-only”

That’s because you declared i as a const which means that its value can’t ever change.

So doing this:

is going to throw an error.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.