FreeCodeCampChina / freecodecamp.cn

FCC China open source codebase and curriculum. Learn to code and help nonprofits.

Home Page:https://fcc.asia/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Profile Lookup 无法通过此关 提示错误"Bob" “number” 没有返回“No”

SnejanaYao opened this issue · comments

//初始化变量
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"]
}
];

var nTrue = false;
var pTrue = false;
var propValue= "";
function lookUp(firstName, prop){
// 请把你的代码写在这条注释以下
var name="";
for(var i=0;i<contacts.length;i++){
name = contacts[i].firstName;
if(name == firstName){
nTrue = true;
pTrue = contacts[i].hasOwnProperty(prop);
if(pTrue){
propValue = contacts[i][prop];
//propValue = "nTrue=" + nTrue + " pTrue=" + pTrue + " propValue=" + propValue;
}
}
}

if(!nTrue){
return "No such contact";
//return propValue = "nTrue=" + "No such contact" + " pTrue=" + pTrue + " propValue=" + propValue;
}
if(!pTrue){
return "No such property";
//propValue = "nTrue=" + nTrue + " pTrue=" + "No such property" + " propValue=" + propValue;
}

return propValue;

// 请把你的代码写在这条注释以上
}
// 你可以修改这一行来测试你的代码
lookUp("Bob", "number");

明明测试结果 Bob number 返回了 “No such contat”得字符串 可是此关我无法通过。

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

什么意思呢 我写的代码都要写在“// 请把你的代码写在这条注释以下” 和 “// 请把你的代码写在这条注释以上” 之间么 。如果是这样的话我得代码是这么写的啊

是要写到注释之间啊。这些代码你并没有写到注释之间:

var nTrue = false;
var pTrue = false;
var propValue= "";