For, Do, and While loops Review


#1


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


The error message I get is SyntaxError: Unexpected token:


for (var i = 1; i < 11; i++) {
    
    console.log(i);
}
var yogi = true;
while(yogi){
    console.log("Hey");
    yogi = false;
}
var yogi = false;
do{
    console.log("Booyah!"):
}(yogi);


#2

Hi the do while statement has that structure

do {
   #do something
} while(condition)

#3

You are missing the while keyword in the last line and you have placed a

: instead of ; here  
console.log("Booyah!"):

Here is full code

for (var i = 1; i < 11; i++) {
    
    console.log(i);
}
var yogi = true;
while(yogi){
    console.log("Hey");
    yogi = false;
}
var yogi = false;
do{
    console.log("Booyah!");
} while (yogi);

#5

I corrected the code and I still get an error message saying console.log is not a function.

[code}

for (var i = 1; i < 11; i++) {

console.log(i);

}
var yogi = true;
while(yogi){
console.log("Hey");
yogi = false;
}
var yogi = false;
do{
console.log("Booyah!");
}while(yogi);

{/code}


#6

There should not be any error....It's running fine here at my end


#7

Haha a refresh to Chrome did the trick. Thanks.


#8

console.log is not a function

This might happen when you use

 console.log = (value)

and what happens is that console.log gets overwritten by the value so it is no longer a function. And as you realized yourself, the javaScript is resetted when you reload the page.


#9

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