Crashes after infinite loop. Why?


#1


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

So, I was asked to complete the condition, but it runs an infinite loop and my browser crashes everytime I click on save and submit code. What am I doing wrong?

var understand = true;

while( understand = true){
    console.log("I'm learning while loops!");
    understand = false;
}


#2

var understand = true;

while( understand === true){
console.log("I'm learning while loops!");
understand = false;
}

Maybe you mean sign === assignment?


#3

Yes = assigns a value so

understand = true

has makes understand become true and as a side effect the whole statement has a value of true itself (because that is the value that is assigned.). So as @webhero said replace the = with a == or === to compare the values instead of assigning a value.


#4

Oops. You're right, thanks!


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.