Lesson 2. While Syntax (Please help!)


#1

Every time i run this code, my browser crashes, like it does with an infinite loop. I'm not entirely certain what is happening, and every time I try something different, it crashes. Please help if you can!


#2

You have an infinite loop. Post your code, or we can't help you.


#3

Sorry. Slipped my mind. I copied it but never pasted it.

var understand = true;

while( "I'm learning while loops!" ){
console.log();
understand = false;
}


#4

I think you are confused, here is while syntax:

while (condition) {
//Statements
//Change Condition
};

You have a string as a condition, which will always be true.


#5

var understand = true;

while( ){
console.log("I'm learning while loops!");
understand = false;
}
Syntax error: Unexpected token )

Not entirely certain where I made the mistake.


#6

You left out the condition in your loop.


#7

Thanks. Guess this is what happens when you stay on Codecademy for more than 12 hours.


#8

12 hours? Amateur! (jk) :slightly_smiling:


#9

In my defense I'm doing this on 4 hours of sleep. :stuck_out_tongue:


#10

Fair enough! :slightly_smiling:


#11

The code is:

var understand = true;

while (understand === true) {
console.log("I'm learning while loops!");
understand = false;
}


#12

It isn't necessary to put understand === true, just put understand.