12. functions if/else NEED HELP


#1

Need help.

// 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 
{
    (numHours <8) 
    return"Get some more shut eye!";
}
console.log (sleepCheck(10);
console.log (sleepCheck(5));
console.log (sleepCheck(8));

#2

Remove (numHours <8)


#3

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

still no good for them.


#4

change your

console.log (sleepCheck(10);

into

console.log (sleepCheck(10));

#5

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

changed; still error.


#6

@kevinnwogu,

What is the MESSAGE....
and
put in a space after your return


#7

SyntaxError: Unexpected token


#8

added space still came up the same


#9

@kevinnwogu,

Your function definition

var sleepCheck = function(numHours);

should be

 var sleepCheck = function(numHours) {
    //and at the END a closing curly bracket
 }

#10

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

illegal return statement


#11
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!";

  }
};

#12

the FUNCTION talk

var myFunc = function( param1, param2) {
       //Begin of  anonymous FUNCTION-BODY
       //VARIABLE -myFunc- has an -anonymous function- assigned
       //this -anonymous function- has 2 PARAMETERS param1 and param2
       //param1 and param2 PARAMETERS are used 
       //as -local- VARIABLES throughout the FUNCTION-BODY

      console.log( param1 + " and " + param2 ) ;

      //End of anonymous FUNCTION-BODY
};

If you want to call/execute the anonymous function
you will have to add a pair of parentheses to the variable myFunc
like
myFunc();
As the anonymous function was defined
as having 2 parameters
you have to provide 2 arguments
in our case 2 string VALUES "Alena" and "Lauren"
like
myFunc("Alena","Lauren");

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**


#13

Thanks that helped. I got it now.
Can you explain why I had to add an extra
}; following a }, however?


#14

@kevinnwogu,

You are placing the IF ELSE statement

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

  }

in the FUNCTION-BODY

var sleepCheck = function(numHours) {
         //FUNCTION-BODY
}

#16