Why does my While Loop Crash?


#1


https://codeacademy.com/en/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661

Not getting any error messages; it just crashes. I get stuck on trivial things often so don't be surprised if I'm missing something obvious. Thanks.


var x = 1;
while (x < 21) {
    console.log(x);
    if (x % 3 === 0 && x % 5 === 0) {
        console.log("FizzBuzz");
    }
    else if (x % 5 === 0) {
        console.log("Buzz");
    }
    else if (x % 3 === 0) {
        console.log("Fizz");
    }
    else { x++;
}
};


#2

Because this is in the else branch, it only gets up to x = 3 and then gets stuck in an infinite loop.

   // ...

    } else {
        console.log(x);
    }
    x++;
}

#3

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