12. Functions & if / else STUCK PLEASE HELP 12


#1

var sleepCheck = function (numHours){

if (numHours >= 8) {

console.log("You're getting plenty of sleep! May be even too much!");
}
else
{
console.log ("get some more shut eye!");
}
};
console.log (sleepCheck(10));
console.log (sleepCheck(5));
console.log (sleepCheck(8));


#2

Please help as I have no clue how to change it, sitting on it for last 2 h

Many thanks
A


#3

Your message is slightly different from what they ask you to print.

Copy the two versions and put them on separate lines to compare them if not immediately obvious.
Copy the two versions and put them on separate lines to conpare them if not immediately obvious.


#4

both of them do not work due to the same error


#5

both of them are wrong


#6

Both of which?
Make sure you're using the correct string and if there are still errors we can go from there


#7

at the moment I have code :slightly_smiling:
var sleepCheck = function (numHours);{

if (numHours >= 8) {
{

return"You're getting plenty of sleep! May be even too much!";

}
else {
return"get some more shut eye!";

};
console.log (sleepCheck(10));
console.log (sleepCheck(5));
console.log (sleepCheck(8));

and I get the message that there is a problem with my syntax, just do not know where
I had tried to check semi- colons and} no success still


#8

now , i have this:

var sleepCheck = function (numHours);{

if (numHours >= 8) {

return "You're getting plenty of sleep! May be even too much!";

}
else {
return "get some more shut eye!";
}
};
console.log (sleepCheck(10));
console.log (sleepCheck(5));
console.log (sleepCheck(8));


#9


#10

the same problem ? with syntax ( Nothing prints on the console)


#11

SyntaxError: Unexpected token.

? What are your suggestions?


#12

var sleepCheck = function (numHours){;
if (numHours >= 8) {
return "You're getting plenty of sleep! May be even too much!";
}
else {
return "get some more shut eye!";
}
};
console.log (sleepCheck(10));
console.log (sleepCheck(5));
console.log (sleepCheck(8));

I HAVE THIS CODE NOW, IT PRINTS BUT I CAN NO GO FUTHER:(((((( PLEASE HELP!!!


#13

Fix the string so it matches what they ask for.


#14

I do not understand , which string?
LINE 3 OR 6??


#15

An easy way to find out is to just compare them.


#16

i do compare them and DO NOT SEE THE DIFFERENCE


#17

If you put the correct and incorrect versions each on their own lines like in my example above, it should be fairly easy to find.

You can also simply copy the correct one into your code.

Details matter when it comes to programming, so finding little differences is an important skill.


#18

hi , after 3 h I got it right! Hurray


#19

HELP!!!!
what is wrong with this:
var sleepCheck = function (numHours){

if (numHours >= 8) {
return "You're getting plenty of sleep! May be even too much!";

}
else {
return "Get some more shut eye!";
}

console.log (sleepCheck(10))
console.log (sleepCheck(5))
console.log (sleepCheck(8))


#20

I was making the exact same mistake for over 3 hrs. @tarikjaber, check line 4 and make sure that the text matches the one they ask for. @ionatan Thanks. This really helped me.