Javascript While Loop


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/0/1?curriculum_id=506324b3a7dffd00020bf661


Hi everyone, I'm a beginner, I'm having trouble with making this while loop (Javasript) work, its for the exercise in the link below.
Please help me know where I'm writing it wrong or with a better alternative while loop. Thank you.
The code I'm using is:


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

var soloLoop = function(myNumber){
  //Your code goes here!
  while(myNumber<=5) {
      console.log("Looped once!");
      soloLoop*2;
      };

soloLoop(3);

PS: I also tried changing the word 'soloLoop' below the console.log to 'myNumber' but that dint work either.
Thanks.


#2

You need to create an initial condition that is true, for example:

var hiHo = true;

and then do your while loop simpler, like this:

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

ths code tells the computer that as long as var hiHo true, it should execute the while loop
thus, hiHo becomes false and the while loop no longer runs, only logging "Looped once!" ONCE.


#3

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