41 Star 244 Fork 69

FreeCodeCamp / freecodecamp.cn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
leanTest.js 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
huluoyang 提交于 2016-05-30 17:44 . add
//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 lookUp(firstName, prop){
// Only change code below this line
for(var i in contacts){
if(contacts[i].firstName == firstName){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else{
return "No such property";
}
}else{
return "No such contact";
}
}
// Only change code above this line
}
// Change these values to test your function
lookUp("Akira", "likes");
JavaScript
1
https://gitee.com/freecodecamp/freecodecamp.cn.git
git@gitee.com:freecodecamp/freecodecamp.cn.git
freecodecamp
freecodecamp.cn
freecodecamp.cn
dev

搜索帮助