How to solove this problem

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

// Setup
var myArr = [];
//check that variable names are spelled properly
var i = 10;
// Only change code below this line.
do { 
 myArr.push(i); 
 i++;
}while(i<5) // changed 1 to 11 } while (i < 10); // since i started at 10 the loop will end before it does anything // while (i < 11); // runs as long as i is less than 11 // while (i <= 10); // also works
   **Your browser information:**

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

Challenge: Iterate with JavaScript Do…While Loops

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

1 Like

first syntatically edit the loop, so it resembles a do...while and not just a while loop. Remember how do...while works. It will execure the code once, then it will check if the while statement is true and if so, it will iterate thru the code again; this repeats until the while statement returns false.
So, we have i=10, the do...while loop will run once and push 10 inside myArr. It will also add 1 to i, which will become 11. At this point we have reached the challenge requirements and need to break the loop. Think of a condition which will return false after the first iteration of the loop, so it will break it and i will remain 11 and myArr will remain [10].

1 Like

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