When to 'while' and when to 'for'


#1

I can't tell what I'm doing wrong...

"sleepy = true;

var loop = function();
while(sleepy);
console.log("Sentence here is a random sentence!")
sleepy = false

loop ();

for(var i=0; i<10; i++; ) {
console.log(i);
} "


#2

Hi first your function loop() should be like that

var loop = function() {#open the function loop

#Here put the while loop

}#close the function loop

then inside it the while loop should have that structure

while(condition) { #open the while loop

}#close the while loo

#3

Got it! It was accepted but for some reason it only printed as "1 2 3 4 5 6 7 8 9 10" with no sentence. But here it is:

"sleepy = true;

var loop = function() {

while(sleepy);{
    console.log("Sentence here is a random sentence!")
}

sleepy = false;
loop ();
}

for(var i=0; i<10; i++) {
console.log(i);
} "


#4

the while loop

var loop = function() {
    while(sleepy);{
       console.log("Sentence here is a random sentence!")
    }
     sleepy = false;
loop ();
}

this line

sleepy = false;

should be inside the while loop and remove the ; after the while condition

while(sleepy); <--- {
   console.log("Sentence here is a random sentence!");
   sleepy = false;
};

then this line

loop ();

should be outside the function

var loop = function() {

#here put the while loop

}
#here put the call function
loop();