Iterate with JavaScript Do...While Loops 1

Iterate with JavaScript Do...While Loops 1
0.0 0

#1

Tell us what’s happening:

What could be wrong here ?

Your code so far


// Setup
var myArray = [];
var i = 10;

// Only change code below this line.
do {
myArray.push(i);
i++;
while (i < 10); 
}

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-do---while-loops


#2

You forgot your closing bracket } before while


#3

Yeah i have given the } after while , But still doesn’t work


#4

i starts at 10, and your while loop now says: hey computer as long as i is smaller than 10, do this. But i is already 10. (the second line of code states it).

so only change your while part and then everything is okay. =)


#5

So are you saying , i should code while

while (i < 10); and everything will be fine ?


#6

No not after but before, like this:

do {
myArray.push(i);
i++;
} while (i < 10);


#7

thanks , got it. i would have known.