Please help on 13/14


#1

Please help on the below syntax, the instructions from the stage are at the bottom, I'm stumped.

var programming = false;

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

happy();

///Declare a variable called programming and set it to false. Then, write an if/else statement inside happy so that happy returns true if programming is false and false otherwise.

?
Hint
Remember: !false is true. Even though programming = false, you can put an expression that evaluates to true (using !) in your if() statement.


#2

could you post a link to the exercise?

anyway, try this..

var programming=false;

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

if you still have any confusion, then let me know.


#3

Guess it's the exercise about not and you're meant to use not aka ! operator to pass instead of a workaround like this:

if (programming = false) {

also it's not a good idea to use an assignment as a condition.


#4

hii,

you mean it should have been "===", am i right?


#5

yes === or at least == . Both compare the value and === is more strict and compares the type as well. But = is an assignement and doesn't compare anything.


#6

understood, thanks for the clarification.


#7

Reference

google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html
= http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide
= http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1


#8

(!programming) worked!, thanks. The need to think outside of the box is becoming more apparent.


#9

More on Control Flow in JS 13/14

// Declare your variable as a global

var programming = false;
  var happy = function()
  {
       if(!programming)     // don't forgot ! operator
  {
    return true;
      }
  else
   {
        return false;
       }
};
happy();           //   happy(!false); < No need passing argument, i do that mistake . thanks to  leonhard_wettengmx_n hi point.

// Try and Run :grinning:


#10

@aexnitin

var programming = false;
  var happy = function()  {
       if(!programming)  {   // don't forgot ! operator
             return true;
       }
       else {
            return false;
       }
};
happy(!false);

The argument !false in your happy()-call is if NO use,
as you did not define the function as taking 1 parameter !!


#11

Ohh, Thanks leonhard_wettengmx_n


#12

Nitin Nikam asked Question : -

can any one explain this code . Please.!.

var phonebookEntry = {};

phonebookEntry.name = 'Oxnard Montalvo';
phonebookEntry.number = '(555) 555-5555';
phonebookEntry.phone = function() {
  console.log('Calling ' + this.name + ' at ' + this.number + '...');
};

phonebookEntry.phone();

#14

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

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

happy(!programming);

This can be solved this way too. "happy" gives the opposite truth value of "programming".


#15

Your version worked for me but i don't get the logic behind that -.-
May you explain in more detail?

Thanks!