Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contacts[i][firstName] 与 contacts[i].firstName 的区别在哪呢? #629

Open
Ccneedmoney opened this issue Jun 24, 2019 · 1 comment

Comments

@Ccneedmoney
Copy link

Challenge Profile Lookup has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

//初始化变量
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 lookUp(firstName, prop){
// 请把你的代码写在这条注释以下
 for(var i=0;i<contacts.length;i++){
  //if(firstName == contacts[i][firstName]){   //使用此句时结果不通过
   if(firstName == contacts[i].firstName){      //使用此句时结果通过
     if(contacts[i].hasOwnProperty(prop)){ return contacts[i][prop];}
     else { return "No such property"; }  
   }  
 }
   return "No such contact";
  

// 请把你的代码写在这条注释以上
}

// 你可以修改这一行来测试你的代码
lookUp("Akira", "likes");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants