12/13 Syntax Error: Unexpected Token!


#1

var sleepCheck = function(numHours); {
if(numHours >= 8){
return"You're getting plenty of sleep! Maybe even too much!";
}
else{
return"Get some more shut eye!";
}
};
console.log(sleepCheck(10));
console.log(sleepCheck(8));
console.log(sleepCheck(5));

It says Syntax Error in the console and "Oops there is something wrong with your syntax"
Please Help Me Guys! Thanks :smiley:


#2

@tempestonlycc3,
If you use a semi-colon-;
and the semi-colon-; is an End-of-Statement indicator
like

var sleepCheck = function(numHours);

the FUNCTION-BODY will never be executed.!!!!

!! Remove the semi-colon-; !!


#3

var sleepCheck = function (numHours) {
if (numHours >=8) {
return "you're getting plenty of sleep! Maybe even too much!";}
else {
return "get some more shut eye!";}
}

sleepCheck(10);

sleepCheck(5);

sleepCheck(8);

what is wrong here ?
says that dont appears "you are getting pretty..."


#4

@joomarcosxavierlavag,
-1
You will have to use the EXACT text's as is mentioned in the Instructions....

-2
As you are using the return statement
you will have to use

console.log( sleepCheck(10) );

to get a Display of the result.


#6

Hey guys i fixed it but have another problem!
Rock, Paper, Scissors 7/9

else if(choice1 === "paper"){
if(choice2 === "rock"){
return"paper wins";
}
else{
return"scissors win";
}

It says Unexpected token: else


#7

@tempestonlym3,

You will have to give us the FULL code
as the error-message =Unexpected token: else=
points to the fact,
that somewhere in your IF ELSE IF statement structure
you are closing the statement and the Javascript interpreter doesnot expect an ELSE.

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#8

Will this work?

var compare = function(choice1, choice2){
if(choice1 === choice2){
return"The result is a tie!";
}
else if(choice1 === "rock") {

if(choice2 === "scissors") {
    return "rock wins";
}
else {
    return "paper wins";
}
else if(choice1 === "paper"){
    if(choice2 === "rock"){
        return"paper wins";
    }
else {
        return "scissors win";
    }
}

 }

};


#9

remove console.log()
when calling a function return you just need the function and parameter:
sleepCheck(10);
At least that worked for me. Give it a try!


#10

@tempestonlym3,
you are distributingn the closing-curly-brackets-} as candy.....

With the curly-brackets-{ } you encapsulate so-called code-blocks....

Have a read in =6b= link
in http://discuss.codecademy.com/t/12-13-syntax-error-unexpected-token/25142/7?u=leonhard.wettengmx.n
and look at the IF ELSE-IF ELSE-IF statement structure.....


#12

Capital Y for You're

Capital G for Get

This exercise is picky for the correct punctuation and grammar


#13

So what do i do to fix it? can you show me?


#14

I didnt knew that, thanks !


#15

I fixed it:)

The Code:

Spoiler Alert

var compare = function (choice1,choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!";
    }
    else if (choice1 === "rock") {

    if (choice2 === "scissors") {
        return "rock wins";
    }
        else
    {
        return "paper wins";
    }
    }

    else if (choice1 === "paper") {
    if (choice2 === "rock") {
        return "paper wins";
    }
    else
    {
        return "scissors wins";
    }
}
};


#16

sorry, I didn't realize the spoiler !


#17

RIP lol That is Something