When to 'while' and when to 'for' - Syntax error?


#1


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


SyntaxError: Unexpected token )


var a=1
    while (a=1){
        console.log("Hi");
        a=0;
    }

for(d=0,d<10,d++){
    console.log("NUMBER "d);
}


#2

Is this your full code? I can't find any out of place parenthesis in this.


#3

 while (a=1)  // should be   while (a==1)

for loop syntax:

for (statement 1; statement 2; statement 3) {
    code block to be executed
}

so here

for(d=0,d<10,d++) // write ; instead of ,

next

```
console.log("NUMBER "d); // you should add like console.log("NUMBER " + d)

`


#4

Copy+pasted from top to bottom. This is why I'm so confused. I think the editor must be searching for some other condition. The one thing I did notice since submitting this is that the for loop should have semicolons instead of colons, but still failing after I changed that. I'll repost the code just to verify

var a=1
while (a=1){
console.log("Hi");
a=0;
}

for(d=0;d<10;d++:wink:{
console.log("NUMBER "d);
}


#5

Thanks for the help! It's all working now [:blush:]


#6

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