3. While Loop


#1



var i = 5;
while(i)
{ console.log("less than 10");
(i == 10) ;
}

why does this while loop produce an infinite loop? how can i correct?


Replace this line with your code.


#2

You either need to fix:
(i == 10);
to:
i = 10;

or set the while loop to actually check something? It may be doing the following:

// first pass
var i = 5;

while(5) {
console.log("less than 10");
i = 10;
}

// second pass
while(10) {
console.log("less than 10");
i = 10;
};

So you could go:

while (i < 10) {
console.log("less than 10");
i = 10
};

Haven't tested either of those but I think one of those will fix it.