12/13 Functions & if/else


#1

can someone please help me im stuck on 12/13 functions & if/else, I'm not sure what i am doing wrong here but it keeps saying something is wrong with your syntax and I have been looking at other people's codes and they are the same. Here is my code

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);
sleepCheck(5);
sleepCheck(8);


#2

var sleepCheck = function (numHours) {
    // the function is missing a code body
};

You may remove the semi-colon from the if-else statement:

    if () {
    
    } else {

    }

#3

didn't work i tried :confused:


#4

Does your code look like this, now?

var sleepCheck = function (numHours) {
    if () {
    
    } else {

    }
};

#5

yes it looks like that


#6

We will need to see your code, again. Please.


#7

i got it right I showed this to a friend and it took us an hour to get it right


#8

Hopefully you learned more than just the correct solution. These courses will be rough going, otherwise. The SCT can be pretty unforgiving. Sadly, it takes away from the true coding experience but it has a purpose, all the same. Learn from it and you will be rewarded.


#9

well I kinda don't know what went wrong when we change it it looks the same...


#10

this time it looks like
the only difference was the {} but they don't make sense to me

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);
sleepCheck(5);
sleepCheck(8);

#11

A fundamental part of JavaScript is { and } denoting object and code bodies. Leave them out and you change everything.