Type error in java script


#1

i am getting type error happy is not a function
here is the code
var programming=false;
var prog= happy(programming);// Declare your variables here!

var happy = function(progg) {
if(progg===!true)
{
return true;

    }

else{
return false;
}
};


#2

Hi, next time please use the </> tag to properly display your code.

Your code using the </> code tag.

The first issue I noticed is this: ===!

There is no such operator. Were you trying to compare using !== ? This means check if the condition is not equal in value or not equal in type. After looking for your code, I think you mean to use the === operator to on the operands progg and !true

I think the above issue illustrates how important it is to follow standard programming style. That is, always place a whitespace between operand and operator; always use proper indentation (at least 2 whitespaces, or use a TAB).

operand = operator
something > something
something >= something
something === something
something === !something

Another thing is, typically you define your functions before using them, so move your function definition code to before the function call.

With that, here's your code:

var programming = false;

var happy = function(progg) {
  // here, progg would be boolean false, which would be compared
  // to !true (NOT TRUE, which is false). Note ! is the NOT unary 
  // operator (only acts on one operand).
  // because false is equal in type and in value to !true, which is false, 
  // the condition would be true; the function would return true
  if(progg === !true) {
    return true;
  }
  else {
    return false;
  }
};

// gives boolean false as an argument to function called happy
//  and assigns that return value to the variable prog
var prog = happy(programming); // Declare your variables here!

// Maybe put this for debug purposes
// (just to test the output, for e.g. using Node.js)
console.log(prog);

Program output using Node.js:

nbk@somewhere:~/dev/JavaScript$ node not_true.js 
true

#3

1st thank you for your response
i did the following change
var programming=false;
var happy = function(progg) {
if(progg === !true)
{
return true;

    }

else{
return false;
}
};
var prog= happy(programming);
console.log(prog)

it gives me output as true .which is the desired output as per the instructions if i m not mistaken.
instructions:
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.
but still it is showing me the following error:
Oops, try again. It looks like your happy function returns false instead of true when programming is false


#4

Try changing !true to false. It looks more intuitive. Also, change progg to programming. Maybe it's just a problem with the Codecademy interface, that requires you use specific names for your variables.


#5

And that still doesn't work, try this if statement:

if (!programming)

which is equivalent to

if (programming === false)