Profile Lookup not accepting my for in loop

Profile Lookup not accepting my for in loop
0.0 0

#1

Tell us what’s happening:

For some reason the challenge is not passing anything but if I test it in my text editor(vscode) it works. Is it because of the for of loop?

Your code so far


function lookUpProfile(name, prop){
// Only change code below this line
let stat = '';



for(person of contacts) {
  if(person.firstName === name && person[prop]) {
    return stat = person[prop];
  } else {
    if(prop === 'address') {
      stat = 'No such property'
    } else {
      stat = 'No such contact'
    }
    
  }
}

//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["JavaScript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(name, prop){
// Only change code below this line
let stat = '';



for(person of contacts) {
  if(person.firstName === name && person[prop]) {
    return stat = person[prop];
  } else {
    if(prop === 'address') {
      stat = 'No such property'
    } else {
      stat = 'No such contact'
    }
    
  }
}

return stat;


// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup/


#2

Ok so I changed my for of loop into a regular for loop that looks like this and I’m able to pass the challenge.
So how come it didn’t accept the for of loop, is it a bug?

for(let i = 0; i < contacts.length; i++) {
  if(contacts[i].firstName === name && contacts[i][prop]) {
    return stat = contacts[i][prop];
  } else {
    if(prop === 'address') {
      stat = 'No such property'
    } else {
      stat = 'No such contact'
    }
    
  }
}

#3

You should have used let or var before person in the following line.

for(person of contacts) {

#4

You just needed to change your for…of to for(let person of contacts) { and it passes.