Was just experimenting. Need Help


#1


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.

https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/0/3?curriculum_id=506324b3a7dffd00020bf661


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");
    }
}


#2

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


#3

Yeah. I got it. Thanks again :slight_smile:


#4