Intro To JS 12:Functions and If/else


#1


Intro To JS 12:Functions and If/else


Oops, try again. There was a problem with your syntax.
SyntaxError: Unexpected token function

var function=sleepCheck(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 function=sleepCheck(numHours) //remove this line

take a variable named sleepCheck and function in it. like

var sleepCheck = function (numHours)

and your statement should be ditto.


#3

It's the same with me. Unexpected token. My code is write. I don't know what the ■■■■ is wrong.

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


#4

var sleepCheck = function(numHours); //remove ;

#5

Wait,, I think I got it. I accidentally stop the code with semicolon right after the parameters. Hahaha :smiley:


#6

I think there is something wrong. sleepCheck is returning as I expected but, an error shows claiming it doesn't return when numHours is 10.


#7

see the instruction copy the return statement and paste in your code.it should be same even a space


#8

Thanks for the reply. I refresh the page and reset the code and alas! It worked with my previous code.


#9

Thanks buddy!
I tried this one too
var sleepCheck= function sleepCheck(numHours)


#10

Please refrain from cursing,

Thanks.


#11

Same for me. It doesn't follow normal typing rules (two spaces at the end of a sentence). In this instruction, it only calls for one space. Silly programmer validation routine.


#12

I'm still having this problem and copy and pasting is not working


#13

Here is my code, I've tried rearranging everything so I wouldn't be surprised if there's something strange in there. I can't get the code to run past 'sleepCheck(10)', any help would be so much appreciated.

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


#14

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