11. Review; What am I missing?


#1


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


I have made multiple changes and whenever I try to run the code, it freezes the browser tab, and I cannot discern why. Any help would be greatly appreciated ^^


var light = "Twilight";

for (var i = 0; i < 9; i +=4) {
    console.log("クルクル");
};

var light = true

while (light = true) {
    console.log("回る~");
    light = false;
};

var light = true

do {
    console.log("飛ばせ!");
} while (light);


#2

1.Remove the space between i and +=4 in your for loop so it looks like this:

for (var i = 0; i < 9; i+=4)

2.Change the last var light to false.
Should look like this:

var light = false

do {
    console.log("飛ばせ!");
} while (light);

You caused an infinite loop in your do and for loop.


#3

Thank you for the reply!

I tried this, but it is still freezing for me.


#4

Change while (light = true) to just while(light) in your while loop.


#5

Thank you!! It finally worked, the end result was this:

var light = "Twilight";

for (var i = 0; i < 9; i+=4) {
console.log("クルクル");
};

var light = true

while (light) {
console.log("回る~");
light = false;
};

var light = false

do {
console.log("飛ばせ!");
} while (light);


#6

Could someone help me figure out what's not working in this do/while loop?

var long = 12;

do {
console.log("Trying");
}
while (long) {
long +=3;
};


#7

I'm not 100% sure how the do/while loop works but, the condition in the while(long) must be false in order to end the loop.
The syntax Codecademy taught you for a do/while loop is

var condition = false 

do {
    // Do something
} while (condition); //Condition MUST be false
// DO NOT manipulate condition further as the loop ENDS

You can also end the do/while loop like this:

do {
    //Do something
} while (5 < 4); // 5 < 4 returns false

#8

From, what I understood, the do part allows it to run at least once before
the while part comes in EVEN if it's false, but I never saw anything about
it needing to be wrong though. Thank you so much for your help


#9

Could be true. I haven't done much with the do/while loop so I don't know the extent of what one can do with it.


#10

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