12. Functions & if/else

Hey guys! I’m having trouble with this exercise, and I don’t know what I’m doing wrong. Also, what does “unexpected token” mean? Thanks.

Hi megan1441, i seem to be having the same problem, were you able to solve it?

Token (in this error) means the semicolon on line three. To fix this just change line three to:

var sleepCheck = function(numHours) {
1 Like

I’m not sure how to fix that. I think when you write in console.log it prints whatever you write after it, and in this case we want it to return either one answer or the other, not both. But I’m stuck as well

i changed it to return and that solved the problem.

megan your if statement doesnt have a bracket surrounding it, why dont you try that and your sleepcheck 8 is missing a seicolon

It took me a real long time to get this one. For some reason you have to put everything after the function in {} and finish it with };. Take a look at my screenshot. I am not sure why this is the case as others did not require this to all be inside {}.

1 Like

Thank you, it worked!!

hello, I seem to be having the same problem.

1 Like

I was having the same problem. English says there are 2 spaces between sentences–at least, that’s how I learned to type. Codecademy wants one space.

return "You're getting plenty of sleep! Maybe even too much!";

Hi devrunner,

I can’t see the bottom of the code from the snapshot and seems ok but have a look at the code below and see if you can identify where the error in your own may be:

var sleepCheck = function(numHours) 

// Inside the function, write an if statement 
if(numHours >= 8)
    // 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!";.
    return "You're getting plenty of sleep! Maybe even too much!";
    //Otherwise (else) if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";
    return "Get some more shut eye!";

// Then call the function with different hours of sleep

You’re getting plenty of sleep! Maybe even too much!
Get some more shut eye!
You’re getting plenty of sleep! Maybe even too much!

hope that helps
also adding snapshot to assist you with comparing code

Hello Brother, please help me with this case , I made all the steps and continuous error. Please check my work and help me correct …

Hey gsus003!,

Trata de quitar el ; de la linea 12 por alguna razon no me lo acceptaba el codigo a mi tampoco de la manera que tu lo tenias escrito.

Just continuing on with @awalklearn’s explanation,

You put “Get some more sleep shut eye!” instead of “Get some more shut eye!”. :smiley:

Doh! Did not see that. Well spotted. Yeah maybe just do what @ragezapper suggests instead! Haha. My bad!

@gsus003 hola.

quizá intente escribir 03 otra vez? Creo que es Cerra lugar de Cierra?

try retyping- 03. { Cerra } ?

1 Like

You talk spanish?
You can help me?
¿Quien puede ayudarme?
There is my code:
Este es mi código:

//Escribí tu función a continuación.
//¡No te olvides de llamar a tu función!
var controlDescanso = function (cantHoras){
if (cantHoras >= 8){
return("¡Estás durmiendo suficiente! ¡Demasiado quizás!");
return("¡Cerrá los ojos un poco más!");

If you can talk to me in spanish is better
Thank you ! :smile_cat:

codemaker46 quita los puntos y coma de las llaves del else y del programa completo

This worked for me:
[It looks like you need “{” after the function is named and “}” with a semicolon after the if/else statement]

// 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!”;