8/11 help


#1

var hello= true;

while(hello) {
console.log("I don't know what I'm doing...")
hello = false
}

for(i=1; i=10; i++) {
console.log(i);
}

It keeps on crashing :frowning:


#2

Hi @hoffma14

If it may help please see the code example below. You're crashing because your for loop is creating the oh so cruel dreaded infinity loop :smile:
A for loop expression is made up of 3 parts in the parens: (I use my own understanding here :smile:)

        //1                              2                       3
for (initiate the variable; evaluate the condition; increment variable) { 
        //the bit of code that occurs each run of the for loop
}

Your initial var is i = 1; and this great you set your starting point, your evaluation check however is not comparing anything and as a result will always be true, and this is where you are having the tiny gremlin. I am not sure if you wanted to go with a not equal "!=", a less then or equal to "<=" so I just choose one for the code example below, however the crucial thing of note is that you have some form of comparison that will be performed in this second step, and most importantly that this check can be set to false so that the loop will end. Finally your incremental is set brilliantly and will increment your variable "i" until that middle comparison check is met and the loop ends.

var hello= true;

while(hello) {
    console.log("I don't know what I'm doing..."); //add some minor semi-colons for syntax tidiness
    hello = false;
}

//updating the for loop will fix your crash, which is due to infinite loop
for(i=1; i<=10; i++) { //your error exists because you are setting 1 = 10 rather then comparing i in an expression
    console.log(i);
}