12. Functions & if / else issue


#28

Maybe have a look at this if this is not enough please open a new thread a name the topic in which you want more details.


#29

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


#31

What


#32

Was this resolved? I'm having the same problem as agentryn,


#33

Probably a typo in the output message. But please do not hijack other peoples thread and rather post code than screen shots here.


#34

A post was split to a new topic: Syntax Error


#35

Guys, why need use condition but not variable in if/else construction?


#36

What do you mean by this?


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

Any help on a syntax error?


#38

this need to be between brackets.

if(numHours >= 8)


#39

I'm having the same issue as agentryn. My code is all correct but I'm still getting the error. I think Codecademy messed up on their output lol

// 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!";
}
}

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);


#40

Ok I figured it out I think. Seems like deleting all the code and re-typing it works.


#41

That's it!!! It's working now!

// 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!";
}
}
var hoursAsleep=sleepCheck(15);
console.log(hoursAsleep)


#42

How could this possibly work if it doesn't look right based on the given instruction? As someone mentioned earlier, it appears Code Academy screwed up on this.


#43

What should be wrong about this?


#44

On my mind there is the confusing way of task. Maybe, it could be better to ask the moderator to correct the text also in that task as to other way" instead:

The first I had typed {else (numHours<8) } (!) and don't understand why it is wrong , there is no logic mistake, no? And it is not the SyntaxError


Just I'd take a look to this post I found the problem, thanks to the all people who posted the Prt Sc
So, the right way is:


#45

The problem is that you use a condition after else. Else is kind of like the default case if the if parts didn't match you pick this. So it doesn't require any condition and having one will just lead to confusion. About the error you receive you might have a look at this:

I see that the exercise is worded more like an else if than an else but explicitly states using an else still how would you word this better? Also if/else statements were part of a previous exercise and you should know them by now so maybe better review this one.


#46

when you call a function you don't need to type console.log()
the only thing that is needed is sleepCheck(10);


#47

when you call a function you don't need to go console.log
all you need is sleepCheck(10);


#48

I need help its saying "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".

and this is my code

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