6/11 why is this wrong?


#1

This is what I have why is it wrong?

//Remember to make your condition true outside the loop!
var dog = true

var soloLoop = function(){
//Your code goes here!
while(dog){
console.log("Looped once!");
var dog = false ;
}
}

soloLoop();


#2

second var is making new variable so you just write your variable without var.
dog = false ;


#3

In this exercise
they want to demonstrate
that if you declare a so-called global variable
( outside of your function )
you are able to access to this global variable
from within the FUNCTION-BODY.

So instead of your declaring
var dog = false ;
you just have to re-assign the dog variable
dog = false ;


#4

I've got a similar problem. Here's what I've got:

var oops=true;
var soloLoop = function(){
//Your code goes here!
while (oops) {
console.log("Looped once!");
};
oops=false;
};
soloLoop();

According to the way my browser crashes, it must be infinite loop but I think in other topics I've seen code like mine work.

Can someone tell me what I'm doing wrong, please?


#5

Your right it's an infinite loop the problem is here:

while (oops) {
      console.log("Looped once!");
  };
  oops=false;

the oops=false; comes after the loop but you'll never reach this as you therefor would need to stop the loop. So move it inside of the loop and it should work.


#6

Oh, I see. Thank you so much!