Help with Challenge(everything be true)

Help with Challenge(everything be true)
0

#1

Is there a reason why the code below is not working ?? I’ve tried every thing.

function truthCheck(collection, pre) {
// Is everyone being true?
for(var i=0;i<collection.length;i++)
{
var obj = collection[i];
for (var prop in obj)
{
if(prop == pre)
{
return true;
}
//return obj[prop];
}
}

return false;
}

truthCheck([{“user”: “Tinky-Winky”, “sex”: “male”}, {“user”: “Dipsy”, “sex”: “male”}, {“user”: “Laa-Laa”, “sex”: “female”}, {“user”: “Po”, “sex”: “female”}], “sex”);


#2

It will return ‘true’ as soon as it finds one prop == pre, but you need to check them all.


#3

isn’t checking them all with the for loop?


#4

In your for loop, once it has found a match it returns that match, exiting the loop. You want to iterate over the entire loop, ensuring that each element is true, then return whether they all are or not only at the end.