我的JavaScript代码有什么问题?
What is wrong with my JavaScript code
下面是我正在做的练习:http://www.codecademy.com/courses/building-an-address-book/0/3?curriculum_id=506324b3a7dffd00020bf661#
Here is my code:
var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};
var contacts = [bob, mary];
// printPerson added here
function printPerson(person){
console.log(firstName);
console.log(lastName);
};
function printPerson(){
console.log(contacts[0]);
}
function printPerson(){
console.log(contacts[1]);
}
var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};
var contacts = [bob, mary];
// printPerson added here
function printPerson(person){
console.log(person.firstName + " "+ person.lastName);
}
printPerson(contacts[0]);
printPerson(contacts[1]);
您希望对代码的最后两部分执行printPerson,而不是重新创建函数
function printPerson(person){
console.log(person.firstName);
console.log(person.lastName);
};
printPerson(contacts[0]);
printPerson(contacts[1]);
你写的
function printPerson(){
console.log(contacts[0]);
}
function printPerson(){
console.log(contacts[1]);
}
你应该写
printPerson(contacts[0]);
printPerson(contacts[1]);
相关文章:
- 我不知道我的编码有什么问题.(JavaScript)
- 什么'这个javascript代码getElementById有问题
- 我的流星路线出了什么问题
- 此nodeValue替换代码有什么问题
- 这个正则表达式的日期/时间有什么问题
- 我的CSS/Javascript下拉菜单测试代码出了什么问题
- 这个代码出了什么问题?(Jquery)
- 下面的Reg表达式出了什么问题
- 鼠标事件,我的代码出了什么问题
- 这个javascript语法有什么问题
- 动态创建foreignGroup并将其添加到svg中有什么问题
- 此代码中动态生成选择框有什么问题
- 我的javascript有什么问题?.className
- 这个 ajax.js 代码有什么问题
- 框架的可用性问题是什么
- JS代码有什么问题,让我知道代码是否可以改进
- 我的 Browserify JavaScript 代码有什么问题
- 图像上传功能将++(+1)副本添加到下一次上传.出了什么问题或如何重置“选定图像”
- 使用 Javascript 动态删除行.我的代码有什么问题
- Ajax jQuery图片上传-新手问题什么是最好的方式来处理这个