12. Functions & if/else


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

keeps giving me SyntaxError: Unexpected token else


#2

For if else this is how you write

if(condition){

}

else{

}


#3

Yes there is something wrong about the {} in the condition. But what is the problem about return?


#4

Sorry misread it .. ignore comment


#5

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(5));
console.log(sleepCheck(8));
its saying unexpected token


#6

I'm stuck on the same lesson.

In your code above, you have the brackets switched after else. It should be:
else {
return "Get some more shut eye!";
}


#7

I keep getting a syntax error and I can't figure out why?

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)


#8

you need to wrap in {} what belongs to your function.


#9

Hello, I can not find the solution for the mistake. could anyone help me?

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

Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator.


#10

You use a strange token in your "You're" better use ' than the backtick `.