Lesson 12


#1



https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661#


Syntax Error: unexpected token if


// Write your function below. 
// Don't forget to call your function!
var sleepCheck = function(numHours)
    if (numHours >= 8) { 
        console.log("You're getting plenty of sleep! Maybe even too much!");
} else { 
    console.log("Get some more shut eye");
};
sleepCheck(10);
console.log(sleepCheck);


#2

you forget to open and close the function
add { after
var sleepCheck = function(numHours)

and then close it before calling the function


#3

like so:

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


#4

also, the error code now is:

SyntaxError: Unexpected token else


#5

you didnt close it
console.log("Get some more shut eye");
};
}
sleepCheck(10);


#6

Same Error msg....

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


#7

now you forgot to add { after

if (numHours >= 8)


#8

ok, I added that and now I get this:

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.

And it's printed this:

You're getting plenty of sleep! Maybe even too much!
[Function]
You're getting plenty of sleep! Maybe even too much!


#9

refresh the browser and check the spelling! and give me the link of the lesson


#10

https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661#


#11

use return keyword instead of console.log also add ! after Get some more shut eye
your code should be like:

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


#12

Thanks for staying with me! That worked so i could continue, but it's printed:

[Function]

Does that make sense?


#13

remove console.log you dnt need it.you consoled sleepcheck that is a function

and see the instruction on that lesson
you have to complete 2 & 3 too


#14

hi, could someone tell me what is wrong with this code..

var sleepCheck = function (numHours);

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

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

...Thank you


#15

Try Adding Brackets { 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);