Can someone tell me where I went wrong?


#1

// Write your function below.
// Don't forget to call your function!

var sleepCheck = function(numHours) {
return numHours >= 8;
console.log(val);
};

if (sleepCheck) {
console.log ("You're getting plenty of sleep! Maybe even too much!");
}
else {
console.log ("Get some more shut eye!");
}

sleepCheck(8);

`


#2

i think you need to put a condition in the if statement, someting like: if (sleepCheck > 6)


#3

I'm not too sure about that as I get a result, it just doesn't change when I put other values when I call my function...


#4

Everything works expect I get a true reading instead of 8


#5

the reason for that is that you ask in youre if statement if there is a sleepCheck value, and there is so he prints oud the sentence. if you change the condition so that it isn't always true, the answer will change.
(sorry for bad english)


#6

Your if/else statement needs to be part of your sleepCheck function. So when you pass a number into sleepCheck, code will execute depending on the if condition.

For example:

var five = function (number) {
if (number = 5){
console.log("the number is 5");
} else {
console.log("the number is not 5");
}
}

five(5);

What code will execute?


#7

@biff75

I tried running it like thing:
var sleepCheck = function(numHours) {

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

Still gives me an error but now I see what you are trying to do, I just can't get it right... Sorry day 3 of Javascript coding still a noob


#8

You're doing fine. What's the error message?


#9

@biff75

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.

it says "get some more shut eye" twice...

and the amount of hours is 10 which means it should say "getting plenty of sleep"


#10

@biff75 dont worry I got it thank you very much for the help


#11

Glad to see you worked it out :slight_smile:


#12

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