12. Functions & if/else


#1

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

console.log (sleepCheck(10));
console.log (sleepCheck(5));
console.log (sleepCheck(8));
}

Here is my code i dont know what went wrong please help thank you
it says There was a problem with your syntax.


#2
// 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!";
}
}

console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

It should work now.


#3

You probably missed or forgot to place opening curly bracket { after if statement and closing curly bracket to wrap your function body. And console.log lines should be placed outside of sleepCheck function.


#4

thanks it works now you da best you smart you very smart you a genuis\


#5

Thanks :slightly_smiling: Unfortunately, I'm not genius, but I'm getting closer :smiley: lol. Good luck to you.


#6

thx right back at you


#7

// 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";
}
}

console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

This my code its showing error and m not able to debug it.
don't know what went wrong.


#8

Hi try to add "!" inside both your return string at the end like that

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


#9

Oh yeah right. code works know. that was a very silly mistake from my side.
Thank you for helping out.