13/14 - error "function returns undefined"


I don't see why the function returns undefined in this:

    // Declare your variables here!
    var programming = false;

    var happy = function() {
      // Add your if/else statement here!
      if(programming === true) 
          return false;

Oops, try again. It looks like your happy function returns undefined instead of true when programming is false

Thanks in advance for your help!


If you do not explicitly return anything then the return value is undefined.

Since your only return statement returns false, perhaps it should be modified to be able to return more than just one value, or perhaps you need more than one return statement.



Between the return false; should be curly brackets because we are writing an if/else statement. Your true next to else also needs curly brackets between it. Make sure on the else that you wrote return true;. Hope this helped you.


the exercise says to return only true or false. and it worked in previous exercises ...


if i add the curly brackets, the error will change into this one:

Oops, try again. It looks like your happy function returns true instead of false when programming is true

Changed the return results and worked, but i don't understand why id behaved like this since there's only one statement for each condition and it worked without the brackets in other exercises. Plus, in PHP, when if/else have only one line each after the condition, it is correct to write the structure without curly brackets.


Well you just wrote true but you need to return true. Also as far as I know this exercise is about practicing the !-operator so making use of it wouldn't be that bad although this works as well.