Problem with syntax out of nowhere :/ 3/12


#1

So this is my code for 3/12. Here's the 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);
And here's the error:
Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator.


#2

you forgot a exclamation mark after too much


#3

... Wow... Just wow... XDD Thanks tho


#4

Now I get another problem...


#5

Oops, try again. It looks like your function doesn't return "Get some more shut eye!" when numHours is 5. Check your if / else syntax and whether you're using the correct comparison operator.


#6

i just get unexpected identifier


#7

And what does that mean?


#8

idk guess it means it doesn't recognize the fact you're trying to call a function


#9

here's mine if it helps:
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 (8)


#10

I think I'm just calling functions wrong... Becouse my log says only one sentance


#11

@megaace13414, your code is really wrong.

@thekristux, your compare operator is wrong. this:

if (numHours => 8) {

should be:

if (numHours >= 8) {

you swapped the > and =


#12

OOOOOHHH so that's the case!


#13

i had it like that b4 still didn't work -.-' thx though :smiley:


#14

Yep. It totaly works now. Thanks for help! Have a nice day both of You :smile:


#15

@thekristux, you are missing some semi-colons after your return statements:

 return "You're getting plenty of sleep! Maybe even too much"; <- missing semi-colon

same with your other return statement
@megaace13414, let's break down your code, problem one, your if statement:

 if numHours => 8

is missing some brackets and you got the > and = the wrong way around

if numHours >= 8)

then your else statement:

else numHours < 8

it is else, else can't check a condition (you have if else for that), so it should be:

else {...}

you don't miss the semi colons, but they are after the curly brackets (}) while they should be after the return statement, like i showed in the beginning of this post to to thekristux


#16

k i had already found and tryed to clear the else statement but at the time i didn't c the brackets needed to be there soo.... many thnx ^^