While Loops: To learn it, you gotta do it 10/11


I am completely lost on this. I don't know why but I keep looking at it like it's Greek. I'm looking at both lesson 9 and 10, and I guess I'm confused as to why in 10 it reads var gettodachoppa = function, but in lesson 9 it's just var loopcondition = false. I believe if it weren't for that I would understand what to do. Thank you for your help in advance.

Lesson 10:
var getToDaChoppa = function(){
  // Write your do/while loop here!


Lesson 9:
var loopCondition = false;

do {
	console.log("I'm gonna stop looping 'cause my condition is " + loopCondition + "!");	
} while (loopCondition);


in lesson 9 you make a do/while loop, in exercise 10 you need to place the do/while loop inside a function.

you could copy the code of exercise 9 inside the function body of 10 if you like. Does adding a function confuse you? function are already covered, right?


Ooooh I see. Yes I covered functions already I just didn't understand I was supposed to put a do/while loop inside a function. I don't know I guess I just wasn't reading it well lol. Thank you so much!


it even says in the comment:

// Write your do/while loop here!

that you need to write the loop inside the function, and surely it is somewhere in the instructions as well, good that you solved it :slight_smile:


Yeah I saw that part and was using lesson 9 as reference for the syntax, but in the instructions, I don't think it mentions doing it inside a function which is why I kept getting lost I think. I think I figured it out but still having syntax errors. This is what I have now and I keep getting syntax error for example:

var getToDaChoppa = function(){
myVariable = true;
do {
console.log("[expletive] this is hard!")
while (myVariable);
getToDaChoppa( );


Good thing you are getting syntax errors or this loop would crash your browser. Never run a loop with a variable set to true. It will never end unless you change the variable inside the loop.

var flag = false;
do {

} while (flag);


Please forgive my ignorance because I really appreciate your help, I don't understand where that section of code would fit in, and what you mean by flag?


It is an arbitrarily chosen variable name that could be anything. I chose that name because it is relatively symbolic of a state, in this case a Boolean state. When choosing variable names, it is always helpful if they are some ways general, and some ways specific, depending on how the code is meant to be read.

The section of code is meant to go inside getToDaChoppa, but I thought that would be obvious. My apologies.


Thank you for bringing more information to this topic for me. Iā€™m truly grateful and really impressed. Really appreciate for your amazing article. Thank you for this valuable information.


That worked!!! Thank you so much for your help!!


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