12. Functions & if else - What am I doing wrong ? Please advice!


#1

Could someone please check the code and see where am I wrong ? The error I get is " SyntaxError: expected expression, got keyword 'else'" . Can't figure out what is wrong! Thanks in advance!


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



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);


#2

if (numHours >=8); <----------- {

so the problem is that you have a " ; " where I put the arrow. just a simple syntax error, but the computer misunderstood it.
just remove the semicolon and it should run


#3

Thank you!! Was stuck forever!!


#4

That helped me, too! Thanks!


#5

No problem!! I'm happy I could help both of you.


#6

Hi, I did exactly same as the code above.
But it didn't work.
So i did the code like below.
It's still not working.
I don't find a syntax error. Please help me out !


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!" ;
}

var advice=sleepCheck(5)
console.log(advice)


#7

Try (numHours) instead of (numhours)


#8

Thanks for the answer.
I tried (numHours) as well as ("") in console.log like below.
but still i get the syntax error.


var advice = sleepCheck(5)
console.log("advice")


#9

Hey everybody,
I'm also having the same problem. I'm getting an error message "SyntaxError: Unexpected token =".
I have tried all the solutions above but still not working. I'll appreciate your help. Thank you!

Here is my code:

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);


#10

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