# 11. Can't find reason for infinite loop

#1

I'm unable to see why I'm getting an infinite loop.
After printing the numbers 6 - 10 to the screen my understanding is that the computer should find a random number between 1-10 and print this to the console next.

Then it should print "rolling" and if x (the random number above) is less than 5 it should print x and "Roll again" to the console before determining another random number and repeating the while loop until x is greater than 5, at which point it should print it's "done rolling".

Thoughts? I spend hours on these little mistakes.

``````// Write your code below!
for ( var i = 6 ; i < 11 ; i++) {
console.log(i);
}

var x = Math.floor(Math.random() * 10 + 1);
console.log(x);

do {
console.log("Rolling");
} while (x < 5 ) {
console.log(x);
console.log("Roll again");
var x = Math.floor(Math.random() * 10 + 1);
}
console.log("I'm done rolling.");``````

#2

you can't do what you are trying to do.

you have a while loop:

``````while (condition){
// do something
}``````

and a do while loop:

``````do {
// do something
} while (condition)``````

you can't just merge them together, that is not how it works

#3

I still don't get it. Can you use my example and show me how it should be done?

Can the while condition not contain any more than the condition itself?

#4

i showed you how a do while loop looks (condition is just a key holder word for an actual condition), i also showed you a while loop, but what you did:

``````do {
// do something
} while (condition){
// do something
}``````

is squeeze together a do while loop and a while loop, which you can't do! The while can't be from and a while loop and a do while loop