10/11 Infinite loop


This is my code for the 10/11.

var getToDaChoppa = function(i){
// Write your do/while loop here!
do {
i = "Hi"

while(i === "Hi") {
console.log("I think I understand...?");
var i = "Bye"


Somehow, this is a infinite loop, even though I changed i to "Bye" on the 9th line.
What am I doing wrong?


A do while loop runs until the argument in the while is false

i = "Hi" // bye is overwritten with Hi
while(i === "Hi") // this is true and the loop begins again

So while is never false and you have a infinite loop


I believe I understand now. Thanks for the reply! :smile: