The error message says there is an unexpected token, 'if' but I only have 'if' were they told me to


#1

As said in the title, the console is telling me that 'if' is an unexpected token, but I am pretty sure I only have 'if' were it is supposed to be. Are there any really smart and awesome people out there that can help?

Here's 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);

Console says:

SyntaxError: Unexpected token if


#2

I'm far from an expert :wink: But whel i look at your code i think you miss a semicolon ( ; ) after the declaration of your variable. So insert an ; just after: var sleepCheck = function (numHours) And i think your problem will be over.

Hope this helps.


#3

I did that, but it still says somethings wrong, it says that there is an unexpected token, but no longer says what the token is.


#4

Hi your function should be like that

var sleepCheck = function (numHours) { 
//Here type your code

}

#5

Hmm, I just did that, now the console says
SyntaxError: Unexpected end of input


#6

He here the instructions

2 Inside the function, write an if statement where if the number of hours of sleep is greater than or equal to 8, the computer will return "You're getting plenty of sleep! Maybe even too much!";.

3,4,5 Call the function with 10 hours of sleep, like this: sleepCheck(10);
Call the function with 5 hours of sleep.
Call the function with 8 hours of sleep.

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

#7

Ok, this is what I have:

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


#8

You should close your sleepCheck function ..... add a } after the else statement


#9

Thanks so much! It worked!