#12 Functions and if/else


#1


Replace this line with your code.


#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!";
}
sleepCheck (10);

What is wrong with this? The console box says: syntaxerror: expected expression, got keyword "if"


#3

Your function syntax is off. It should look something like:

var anyword = function(parameters) {
code here for what the function does
more code
a little more code
}

Learn more here:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function


#4

Thank you! That worked.


#5

I have the same problem.


#7

hey @sparta99, can you post your code in a new topic? be more than happy to help either way :slight_smile:


#8

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