6. Soloflight. SyntaxError: Invalid or unexpected token


#1

please, help!
In my opinion everything is correct

//Remember to make your condition true outside the loop!
i = true;
var soloLoop = function(){
while(i)
{
console.log("Looped once!);
i = false;
}
};

soloLoop();


#2

You defined i. But did you also declare i with var i?


#3

So does not work either.

myCondition = true;
var soloLoop = function(){
while(myCondition)
{
console.log("Looped once!);
myCondition = false;
}
};

soloLoop();


#4

Did you declare your variable myCondition with var myCondition somewhere?


#5

It would not be

var soloLoop = function(){

but rather

function = soloLoop(){

If it doesn't work let me know.


#6

What error does it show(syntax,unexpected token, etc.)?


#7

Nope. In JS, there are only two ways to create functions:
Function declaration:

function hello() {

}

Function definition:

var hello = function() {

};

#8

yes. "SyntaxError: Invalid or unexpected token"
Here with this code

var i = true;
var soloLoop = function(){
while(i)
{
console.log("Looped once!);
i = false;
}
};

soloLoop();


#9

Oh, sorry. I keep on forgetting not to add the equal sign(=). :slight_smile:


#10

Got it! You forgot the end quote on console.log("Looped Once!).


#11

You forgot the closing quotation mark. :slight_smile:


#12

Yes! I was inattentive! Thanks a lot for your help! :slight_smile:


#13

Thank you for your help! Everything worked:slight_smile:


#14

No problem! Just in case you don't know why your emoji didn't show up, you didn't add a space or put it in front of a punctuation mark.

should be

or


#15

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