Profile Lookup


#1

Tell us what’s happening:
请问为什么我不能用map循环?

Your code so far


// 初始化变量
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){
// 请把你的代码写在这条注释以下
  contacts.map(item => {
          if(item.firstName == name){
           if(item.hasOwnProperty(prop)){
                return item[prop]
            } else {
             return "No such property"
            }
          }
         })
        return "No such contact"
// 请把你的代码写在这条注释以上
}

// 你可以修改这一行来测试你的代码
lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.90 Safari/537.36.

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