Introduction to functions if/else


#1

Instructions
Write a function named sleepCheck that takes the parameter numHours
Inside the function, write an if statement 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!";.
Otherwise (else) if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";
Then call the function with different hours of sleep

Call the function with 10 hours of sleep, like this: sleepCheck(10);
Call the function with 5 hours of sleep.
Call the function with 8 hours of sleep.
// Here's what i have
var sleepCheck = function(numHours)
{
if (numHours>=8)
return("You're getting plenty of sleep! Maybe even too much!");
};
{
else (numHours<8)
return("Get some more shut eye!");
};
sleepCheck(10)
sleepCheck(5)
sleepCheck(8)


#2

try this

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

remember this is how the if /else if/ construct runs

if(condition){/*statements*/}
else if(condition){/*statements*/}
else{/*statements*/}

the else block takes no conditions

Also you need console.log() the call to sleep check because you are returning a string statement to the use so you must pass it as a token(argument) to console. log () to see the result.
There would be no need for console.log() if you were doing

console.log("You're getting plenty of sleep! Maybe even too much!");

inside the function implementation rather than

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

#3

Thanks a billion. It was, as usual, telling me meaningless error messages and just "expecting" me to know what the problem was...