12.Functions & if/else


#1

var sleepCheck = function(numHours){
if(number of hours of sleep >= 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));

what's wrong in it? i can't find....please help...


#2

This worked for me:

// Write your function below. 
// Don't forget to call your function!
function sleepCheck(numHours){
if (numHours >= 8) {
  console.log("You're getting plenty of sleep! Maybe even too much!");
} else if (numHours < 8) {
  console.log("Get some shut eye!");
} 
sleepCheck(10);
console.log("You sleep a lot boi!");
sleepCheck(5);
console.log("Sleep more.");
sleepCheck(8);
console.log("Just average, but good.")};

It seems like you need to understand functions, formatting and indentation more, at the least. :slight_smile:


#3

The left side of your if condition should be a variable. Is this all of your code or is there a confirm or prompt statement on a preceding line?


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.