Was just experimenting. Need Help


I was just experimenting. Trying to write a code using "while" loops. Wanted to write a code in which the computer rolls a dice till it gets a 6. If it doesn't get a 6, it rolls the dice again.

Just getting confused because I don't understand why this is an infinite loop.

Plz tell me where did I go wrong.


var rolling = true;
var numberObtained = Math.floor(Math.random()*6) + 1;

while(rolling) {
    if (numberObtained != 6) {
        console.log("Not a six");
       var numberObtained = Math.floor(Math.random()*6) + 1;
    } else {
        console.log("It's a six");


you need to set rolling to false when it's a six so the loop will end

its an infinity loop, because rolling is always true


Yeah. I got it. Thanks again :slight_smile: