Everything Be True

I dont understand why when the number is NaN the result of my code isnt returning false?

link to challenge:

function truthCheck(collection, pre) {
   
  let newArr = []


for (let i = 0; i<collection.length; i++){
newArr.push(collection[i][pre])

}console.log(newArr[0])
console.log(Array.isArray(newArr[0]))

for (let x=0; x<newArr.length; x++){
  if (newArr[x] == false || newArr[x] == undefined || newArr[x] == NaN){
    return false;
  } if (Array.isArray(newArr[0]) == true){
    return true;
  }
}return true;


}

truthCheck ([{name: "Quincy", username: "QuincyLarson"}, {name: "Naomi", username: "nhcarrigan"}, {name: "Camperbot"}], "username") ;

This will never be true.

I would use the concept of truthiness instead of looking for specific values that you know are falsy.

Side note - you should use === instead of ==

I forgot about changing the things i was going to compare to boolean.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.