Everything Be True undefined property value

Tell us what’s happening:
I’m trying to solve this algorithm
When I run my code the property value is undefined
What is wrong with my code?

Your code so far

function truthCheck(collection, pre) {
  // Is everyone being true?
  for(var i = 0; i < collection.length; i++){
  for(var property in collection[i]){
    console.log(property + ': ' + collection[property]);
  return pre;

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:

collection is an array of objects, so trying to write collection[property] does not work. Arrays have indices (0 to the array length -1) . If you were to modify you console.log statement slightly (see below), you what you want.

console.log(property + ': ' + collection[i][property]);
1 Like