12. Functions & if/else Syntax Error Help


#1



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

Can someone please help me with this SyntaxError I keep getting? It is probably something silly but I cannot figure it out. I've tried different browsers and it will not let me continue. Thank you in advance for any advice.

SyntaxError: expected expression, got keyword 'else'


// Write your function below. 
// Don't forget to call your function!
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);


#2

Your after your if closing curly bracket you have a semi colon remove it :slight_smile:


#3

Ah, I knew it was something simple!

Thank you! I'm still not quite sure of the functions yet. I thought you needed to have semicolons after each line. I removed the semicolon after the If and Else and it worked.

Thanks again, it works as below for any one else having issues.

// Write your function below.
// Don't forget to call your function!
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);


#4

thank you you helped but i still can't get it right


#5

If you have a semi colon when closing if statement then the else won't work as they work hand in hand..


#6

Please create new topic with code + lesson + error

Thank you


#7

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(8));
console.log(sleepCheck(3));
console.log(sleepCheck(10));


#8

what is the mistake it shows error


#9

Instead of calling the function three times, it looks like you actually just console logged it. Try deleting the 'console.log' portion and one set of parenthesis and see if it works. Like this:

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);


#10

Hi just remove the space between sleep and !

 "....of sleep !"