Lesson 12


#1

What am I doing wrong here? I cannot for the life of me figure it out.

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

#2

You seem to miss the } that closes the function.


#3

To call the function you should use: sleepCheck(10);
You shouldn't use the console.log
I hope that helps!


#4

Why do you think this? You're not the first to say this, but actually your fine calling it with console.log and it is even better in this case as you could see all 3 outputs whereas 3 function calls only show you the last value due to a console feature echoing the last value. Could you explain your thoughts on this?


#5

Just add one more }; after the else return.. Hope it will work..


#6

Can't figure out what is going wrong with this function? Any ideas?


#7

type this

var sleepCheck = function (numHours) {


#8

also for the else bit do this

else {
return "Get some more shut eye"
}


#9

also add a semi colon at the end of the function.

other than that it should work. as it looks like all your curly braces are present


#10

Thanks for the reply 'chipmaster33692'. I am confused as to why codecademy insists on placing functions within variables. Do you know why?. I have completed the exercise by removing the else (numHours < 8) section. It did not need the other alterations to work. The instructions make it sound like the else section of the statement need the (numHours < 8) written in to the code but if this is added it does not work.

function sleepCheck (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(8));
console.log(sleepCheck(5));


#11

yes i agree some of the instructions aren't exactly clear, as for codecademy making things rather complicated i believe that is because of their rather stringent curriculum to ensure people are getting the best practices in.


#12

Can anyone tell me what I have to do? It outputs the right thing but hey say it's not right?


#13

I had the exact same problem. The program wants you to use the EXACT same sentence, down to the spaces. I had two spaces between "sleep!" and "Maybe". Once I got rid of one of them, it passed.


#14

Thank you citadel17 for clearing that up ! My error was in my if statement i put the wrong parameter :
if (sleepcheck >= 8) instead of if (numHours >= 8).

So here's the right way to go :

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