11. Review - Syntax Error


#1


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


I'm getting a syntax error SyntaxError: Unexpected identifier - and can't quite see where I'm going wrong. Any help appreciated.


for (var x=1;x<10;x++) {
    console.log("counting");
    }

var kev=true;
while(kev) {
    console.log("Hurray");
    kev=false;
}

var i=0;
do {
    console.log("One more time, or so");
i+1;
} while i<5;


#2

I think it's that the condition for your do/while statement needs to be in parenthesis.
like this:

var i=0;
do {
console.log("One more time, or so");
i+1;
} while (i<5);


#3

@xkittyx You would need to change the code after that because it is an infinite loop. You can run it here and see.


#4

Yes it is an infinite loop because i+1 just computes i+1 but doesn't change i. Therefore better use i+=1 or i++.


#5

yes - that's what I was missing - thanks! I couldn't quite see for looking...


#6

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