HELP PLZ! unit 9 lesson 12 "not"


#1

I have been stuck on this for a day or two now plz someone help me out here, I have no idea how to make happy return true if programming is false and false otherwise. I'm just having troubles conceiving the right code here... can someone just give me a quick lesson on this code or show me an example? the sooner the better I've been hung up on this one for a bit!

I tried this but it said happy returns true when programming is true... I'm prolly just being an idiot but I'm confused
// Declare your variables here!
var programming = false;

var happy = function() {
if (programming){
return !false;
}

};


#2

Hmm, your function appears to have a possible case where nothing is returned. A value is only returned if the variable programming is true, but you assigned the value false to it.


#3

@collinball24,

The IF statement

if (condition) {
    //IF codeblock
}

will execute the IF-codeblock
when the IF-condition renders to true

So try it with !programming


#4

it told me to set it to false but i figured it out now thank you anyway!


#5

I got past it now thank you! my only question is why it didnt return any answer on the console, should it have?


#6

@collinball24,
The return statement will return a result with NOdisplay

So you either call the function
like

 var theResult =  happy();
 console.log( theResult );

or

console.log( happy() );

#7

okay thats what i thought but when i used it before it came up! buts its comforting to know im not messing the code up! Thanks alot for your help!


#8

@collinball24,

the FUNCTION talk

var myFunc = function( param1, param2) {
       //Begin of  anonymous FUNCTION-BODY
       //VARIABLE -myFunc- has an -anonymous function- assigned
       //this -anonymous function- has 2 PARAMETERS param1 and param2
       //param1 and param2 PARAMETERS are used 
       //as -local- VARIABLES throughout the FUNCTION-BODY

      console.log( param1 + " and " + param2 ) ;

      //End of anonymous FUNCTION-BODY
};

If you want to call/execute the anonymous function
you will have to add a pair of parentheses to the variable myFunc
like
myFunc();
As the anonymous function was defined
as having 2 parameters
you have to provide 2 arguments
in our case 2 string VALUES "Alena" and "Lauren"
like
myFunc("Alena","Lauren");

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function with 1 parameter using return-statement

var myFunction = function( param1 ) {
       //Begin of FUNCTION-BODY
       //myFunction =function= has 1 PARAMETER param1
       //this param1 PARAMETER is used as a -local- VARIABLE
       //throughout the FUNCTION-BODY

      return param1;

      //End of FUNCTION-BODY
      };

you have defined a myFunction function
which takes 1 parameter param1
this param1 parameter is used
as a variable throughout the FUNCTION-BODY.

If you want to call/execute this myFunction function
and this myFunction function was defined
as having 1 parameter param1
you will have to provide 1 argument
in our case a "number VALUE" 4
myFunction( 4 );

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**

============================================

As you are using the return-statement in your myFunction function
you will only get a return-value no-display.
You can however capture this return-value in a variable
and then use the console.log()-method to do a display.

var theResult = myFunction( 4 );
console.log( theResult );

OR directly

console.log( myFunction( 4 ) );

#9

var programming = false;

var happy=function(){
if( programming != false)
{
return false;
}
else{
return true;

    };

};


#10

The variable programming not equaling false would be the same as programming equaling true. Instead of doing programming != false, you could have just done programming, which is the same thing (returns true when programming is true, and returns false if programming is false. Better yet, you could just do return !programming, though that may not be what the lesson wants.