Struggling with syntax errors on JavaScript Functions & if/else exercise


#1

SyntaxError: Unexpected token {

is the error message.
The code looks like this:

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


#2
  1. You put 'numbHours'.

  2. You logged return.

  3. You have a space in your function declaration.


#3

3.) is ok I guess
4.) else has no condition.


#4

Hi,

Struggling with this one also:

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

sleepCheck(10);

SyntaxError: Unexpected token function

Thanks!


#5

Try var sleepCheck = function(numHours)


#6

I'm stuck here also, getting the following error message:
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.

my code is as follows:
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(8);
sleepCheck(5);

What am I doing wrong here?


#7

The semicolons shouldn't be there :slight_smile:


#8

Thanks! @levibarker It worked perfectly!