12 Function if/else help


#1

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!";
}
}
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

whats wrong?

oh and in console i get=

you're getting plenty of sleep! Maybe even too much!
Get some more shut eye!
you're getting plenty of sleep! Maybe even too much!


#2

The last } that closes a function needs to have a semi-colon at the end like so,

var functionName = function() {

};

#3

Hola, la sintaxis correscta es la siguiente, espero que ayude....

//Escribí tu función a continuación.
//¡No te olvides de llamar a tu función!

var controlDescanso = function(cantHoras){
if (cantHoras >= 8){
return"¡Estás durmiendo suficiente! ¡Demasiado quizás!";
}
else
{
return"¡Cerrá los ojos un poco más!";
}
};
console.log(controlDescanso(10));
console.log(controlDescanso(5));
console.log (controlDescanso(8));


#4

It is telling me that it's not returning the correct answer for numHours = 10, too. But it is returning the correct answer. I've tried leaving out the last two console.logs and doing one at a time, and nothing seems to make the Ooops go away even though the program seems to be functioning correctly. It SEEMS to be, maybe I'm missing something?

// Write your function below.
// Don't forget to call your function!
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!";
}
};

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


#5

Nevermind. I had to copy and paste the return string from the instructions. It didn't like the spacing of mine or something.


#6

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!";
}
};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

i did this and still the samething


#7

never mind it was just spelled wrong :confused: rip


#8

2 posts were split to a new topic: 12. Function if/else "...There was a problem with your syntax."


#10

A post was merged into an existing topic: 12. Function if/else "...There was a problem with your syntax."