Functions and if /else


#1



Replace this line with your code.


var sleepCheck = function(numHours) {
if ( numHours >=8)
{
return " bla bla";
}
else {
return " blahhhhhhhhh";
}
}
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);
why is this wrong?


#2

First things first, what is it doing differently from what you want? "Wrong" doesn't describe that!


#3

The compiler says, "Check your if/else statement and whether i have used correct comparators or not, plus it says," That i am not getting the output of 'if' statement when the "numHours" is 10.


#4

That's something codecademy says, not the interpreter!

Is it saying you should be printing something? You're not, are you? How can you change that?
(No clue what the instructions really say but you mention "output" so perhaps that means printing, not return value, you'll have to refer to the instructions for how it should behave)


#5

Thanks, now i know js is interpreted not compiled.
I corrected it myself, the problem was with the output,each alphabet was supposed to be what it is mentioned in the instruction.


#6

Well it's both, those are really vague terms and to some extent all languages do both, but from a user stand-point we are feeding code to a program that executes it for us, as opposed to generating an executable binary file.
Modern JS interpreters go to great lengths to speed up execution, and it does involve generating machine code.


#9

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