| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 331 人关注过本帖
标题:这段代码怎么运行不起来呢?
只看楼主 加入收藏
苍穹之舞
Rank: 2
等 级:论坛游民
威 望:1
帖 子:55
专家分:20
注 册:2014-10-7
结帖率:86.67%
  已结贴   问题点数:10  回复次数:1   
这段代码怎么运行不起来呢?
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(firstName, prop){

var hasName = false;
for(var i=0;i<contacts.length;i++){
  if(contacts[i].firstName == firstName){
    hasName=true;
   
    if(contacts[i].hasOwnProperty(prop)){
        return contacts[i][prop];
     }else{
        return "No such property";
     }
   
  }
}
if(!hasName){
 return  "No such contact";
}

}


lookUpProfile("Akira", "likes");

2018-12-17 17:33
icecool
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:20
帖 子:1203
专家分:1309
注 册:2005-3-14
  得分:10 
可出运行啊:
document.write(lookUpProfile("Akira", "likes"));

附件: 您没有浏览附件的权限,请 登录注册

loading...
2018-12-19 09:10







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.201014 second(s), 8 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved