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

When I hit submit I get this 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.

What have I done wrong?


"SyntaxError: Unexpected token else"
#2

Hi try to refesh the page..


#3

Just tried that- but unfortunately the same message came up.


#4

try to change browser ..


#5

I'm assuming that means my code is correct? If so I'll just move on to Rock Paper Scissors.

Thanks.


#6

Yes your code is correct.


#8

4 posts were split to a new topic: Says it's not returning when numHours is 5


#9

O problema Ă© que vocĂȘ vocĂȘ estĂĄ tentando imprimir o sleepCheck, quando o que precisa ser impresso Ă© parĂąmetro do IF "You're getting plenty of sleep! Maybe even too much!" ou o parĂąmetro do ELSE "Get some more shut eye!".
AlĂ©m disso a Ășltima chave deve conter ponto e vĂ­rgula.
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);


#10

You call a function by its name like:

sleepCheck();

You can give some input to your function if you like:
SleepCheck(5); 5 is a input here.

You do not need to console.log your (function calling).
You did:

We create function so that we do not need to write console.log or other sort of code again and again . Just change the input and let the function do the work.


#13