6. Solo flight


#1


I don't understand at all this exercise. What would that While loop do?


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


"Oops, try again.Hey now--you have to use a 'while' loop!"


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

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

    soloLoop();

Edit: where is the space for the while loop? What would it do? I have read everything so far by doing these exercises, but I dont understand what is the point of this exercise. What will it do with a function? Why there has to be a function?


#2

where is the space for the while loop?

Inside of the function

What would it do?

Loop (repeat the code in its {} ) until the condition is false

What will it do with a function?

What a function does, run if it is called. No need to bother about it that much.

Why there has to be a function?

No idea. To practice, to make the code inside reusable, maybe it is just easier to test, idk. But as said it is not that important here just write your code in its {}.

And for informations about loops maybe have a look at this:
https://discuss.codecademy.com/t/faq-and-some-explanations-about-loops/1201?u=haxor789


#3

Here is the code that worked for me:
//Remember to make your condition true outside the loop!
soloLoop= true
var soloLoop = function(){
//Your code goes here!
while(soloLoop){
console.log("Looped once!");
soloLoop = false
}
};

soloLoop();
Hope it works! :grin:


#4

Excuse-me guys.
I would like show my code to somebody help-me.
Follow:

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

thank you.


#5

Hi there,

The line "var my_condition = true;" should go outside the loop, on line 2 for example. The starting point needs to be defined outside the loop for it to work.


#6

Also, I think you only need to put: while(my_condition)
There is no need to write: while(my_condition = true) as this is what the while function checks for anyway.
And I think you will also need to add {} to your "while" statement for it to work:
while(my_condition) {
console.log("Looped once!");
my_condition = false;
}
//and then you close the other bracket
};

I hope that makes sense? This is my first time answering on the forums


#7

Thank you so much.

It works.

:wink:


#8

EDIT: Never mind, I found the problem. It was one missing curly bracket.


#9

i don't know what is the wrong???
help!!

var code=true;
var soloLoop= function(){

while(code){
    console.log("looped once!");
    code=false;
}

};

soloLoop();


#10

HI try to refresh the page...


#11

Seems to be ok so far, what error message do you get? Have you tried to refresh the page as @wizmarco suggested?


#12

this is not the problem i refreshed the page 10 times :cry:
ane this the massage error
Oops, try again. It looks like you're not printing the right string to the console


#13

Maybe print looped with an upper case "L"? Really some exercises require exact copying of the mentioned text.


#14

thank you soo much for ur time it is the solution