Basic JavaScript - Iterate Odd Numbers With a For Loop

Tell us what’s happening:
Describe your issue in detail here.
WHENEVER I RUN MY CODE THE WEB PAGE BREAKS WHAT DO I DO??
THIS IS HAPPENING FOE ALL MY “LOOP” CODES
Your code so far

// Setup
const myArray = [];

// Only change code below this line
for(let i=1; i=9; i+=2){
  myArray.push(i);
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Iterate Odd Numbers With a For Loop

Link to the challenge:

You have a console message:

Potential infinite loop detected on line 5. Tests may fail if this is not changed.

This is because you don’t have a stopping condition in your for loop.
You should declare an initial value for i, then a stopping condition, then increment/decrement i.

Here’s how you would push the values 0-10 to an array, using a for loop:

for(let i=0; i<=10; i++){
  myArray.push(i);
}
2 Likes

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