12/14 - code not returning "false"


#1

Hi,

my code:

var tired= true;
var bored= false;

var nap = function() {
if (tired || bored){
return true;
}
else if (!tired || bored){
return false;
}
else{
return true;
}
};

nap(!tired);

code is working and let me go to the next excisize, but it is not returning "false". Whatever parameter I put inside "nap( )" it is returning "true". I think my "else if" returning false is not working, but I do not know why. And not sure why codeacademy accepted this code and let me go to the next excisize;

I would appreciate someone explain me what is wrong with my code, and how I can return "false".

Thank you,


#2

Your code is not in accordance with the instructions given:

Create two variables, tired and bored, and set one equal to true and the other equal to false. (It doesn't matter which is which.) Inside the nap function, create an if statement that returns true if either tired or bored (or both!) are true, and false otherwise.

In an OR expression, the yielded value is always true if any operands are true. So we only need a simple if/else statement.

true || true
true || false
false || true

All of the above yield true

An OR expression will only yield false when no operands are true

Remove the else if statement from your code.

  if (tired || bored) {
    return true;
  } else {
    return false;
  }