Loops - Do/While loops


I have trouble with loops a lot and I don't really know why. I have to keep restarting Chrome and I can't figure out why. I think I am finding a bajillion ways to crash a browser.

var thing = true
var getToDaChoppa = function(){
    do {
        console.log("This is gonna give me an infinity loop");
    } while(thing);  


This doesn't work and I don't know what is wrong. Please help!


Firstly, your var thing = true needs a semicolon (;) at the end simply to maintain valid JavaScript. Now, the reason your browser is crashing is because the loop is continuing to loop for the condition while(thing) where thing is true and is never being changed therefore the loop is never stopping. Do you see that?


Yeah. The while(thing) needs to become false then it will stop. right?


That is correct! If you don't do that, it will keep looping and crash the browser.


so what can I do to stop it?


Well, what do the instructions say to do?


Write a do/while loop inside the function we've created for you, getToDaChoppa. The function should log a string of your choice to the console. do it now!
Exact wording


Since it doesn't tell you to do much more than have it run one time (you can simply infer this), you can stop the behavior you're not wanting by initializing thing with false rather than what you currently have it set as (true).


Yes thanks I figured it out. You can also set the while condition to thing = false in the do statement!