While Loops, lesson 6. Console is not logging


#1


While Loop, Lesson 6

When i execute the code, i receive a prompt box, but it is blank. I do however receive an error asking if I logged "Looped Once" as instructed.


//Remember to make your condition true outside the loop!

var jumbo = true

var soloLoop = function(){
  while (jumbo)
  {
    console.log("Looped once!");

    var jumbo = false;
  }
  
};

soloLoop();


#2

There's no call to prompt in your code, perhaps you're calling some other function that you created earlier.

Your code does not enter the loop, that is because jumbo is undefined when the loop starts.

You have created a local variable named jumbo, it gets defined inside the loop, until then it is undefined and is shadowing your global variable by the same name.


#3

ahhh, i see what you're saying.

The local and global variable are conflicting!

Got it to work. Thanks again!


#4

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