Lesson 12: Functions & if/else


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!";

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"

Hi try to refesh the page..


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


try to change browser ..


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



Yes your code is correct.


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


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


You call a function by its name like:


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.