12. Functions & if / else issue


#1

Hi everyone! I just started on here, and I'm getting this all for the most part, but I've run into a problem.

var sleepCheck = function (numHours) {
if (numHours>=8) {
return "You're getting plenty of sleep! Maybe even too much!";
}
else {
return "Get more shut eye!";
}
}
var hoursAsleep=sleepCheck(15);
console.log(hoursAsleep)

This is what I have. I have it like this and with ; after the last line, and neither let me pass, yet I can switch to 15 hours of sleep, then input 5, and it displays correctly, but still tells me 5 doesn't work.

If anyone has any insight onto what I've got wrong, I would appreciate it. Thank you.


#2

Look into the Instructions
03.
Otherwise (else) if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";

If you add "some" it works fine :smile:


#3

Please help . its not running

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) {
if (sleepCheck (5)>=8) {
return "You're getting plenty of sleep! Maybe even too much!";
}
else {
return "Get more some shut eye!";
}
}


#5

sleepCheck is the name of your function and [Function] >= 8 doesn't work, better use the parameter numHours here.


#6

// I think you need change the following from your code;
if (numHours >= 8)
// the 'sleepCheck(5)' call, I think needs to be right at the end of your code


#7

I'm a little stuck. Why is it telling me 'else' is unexpected?


#8

you have semicolon on unnecessary places like
line 4: if(numHours >= 8) ;
line 6: };
line 9: };

if and end statement shouldn't have semicolon after closing curly braces.

Also, you didn't close the sleepCheck function (there is no curly brace to close that function!)

Hope this helps!


#9

Yep, that worked! Thanks!


#10

Hi, I would like to have the Screenshot result. If possible.Please


#11

Sure


#13


#14

Hi, you have a typo in the returning sentence.

plently should be plenty


#16


Stuck here for a while now cant figure whats wrong


#17

Thank's a lot!!! Curly brackets!!


#18

This worked.. don't know if it's the most proper way.


#20

Thanks it worked :smile:


#21

// Write your function below.
// Don't forget to call your function!
var sleepCheack = function(numHours) {
if (numHours >=8);
return "You're getting plenty of sleep! Maybe even too much!";
}
else {
return "Get some more shut eye!";
}
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));
whats wrong??


#22

No semicolons after conditions see this link for an explanation:


And no cross posting in other peoples thread.


#23

put console.log before sleep check