dimanche 29 mars 2015

If Else and Javascript what am I missing?

I think there is an issue in my if else statement as I think it is giving me the opposite result of what I'm expecting.



console.log(_.map(item, function(n){return _.find(n).tertiary}))
//is undefined.

console.log(_.map(item, function(n){return _.find(n).primary}));
//is ["green"]

I use the following if statement to assign a value to my variable:

if(_.map(item, function(n){return _.find(n).tertiary}) === undefined ){
var audience = _.map(item, function(n){return _.find(n).tertiary});
} else {
var audience = _.map(item, function (n) {return _.find(n).primary});
}

console.log(audience);//this is undefined


Am I doing something wrong or is this working correctly? I expect the answer to be ["green"].


Aucun commentaire:

Enregistrer un commentaire