JavaScript:帮助调试代码 [英] JavaScript: Help with debugging code

查看:56
本文介绍了JavaScript:帮助调试代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一本简单的地址簿。这是我的代码:



var bob = {

firstName:Bob,

lastName: Jones,

phoneNumber:(650)777-7777,

电子邮件:bob.jones@example.com

} ;



var mary = {

firstName:Mary,

lastName:Johnson,

phoneNumber:(650)888-8888,

电子邮件:mary.johnson@example.com

};



var contacts = [bob,mary];



function printPerson(person){

console.log(person.firstName ++ person.lastName);

}



函数列表(){

var contactsLength = contacts.length;

for(var i = 0; i< contactsLength; i ++){

printPerson(contacts [i] );

}

};



/ *创建搜索功能

然后称它为Jones* /

函数搜索(lastName){

var contac tsLength = contacts.length;

for(var i = 0;我< contactsLength; i ++){

if(contacts = person.Lastname){

printPerson(contacts [i]);

}

}

};

搜索(jones);

#---------- -----------------

我在想我的代码是搜索功能。对于搜索功能,我想通过拨打他的姓氏来联系我的联系人,并仅从我的联系人那里接收该人。为什么这段代码有问题?如果可以,请帮助调试此代码。谢谢你的时间!



[重新发布为什么会发生这种情况? Js [ ^ ] - SA]

I'm working on a simple Address book. 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];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}

function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
};

/*Create a search function
then call it passing "Jones"*/
function search(lastName) {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength;i++) {
if(contacts = person.Lastname) {
printPerson(contacts[i]);
}
}
};
search("jones");
#---------------------------
I'm thinking the problem with my code is the search function. For the search function, I want to get a person in my contacts by calling his last name, and receiving only that person from my contacts. Why is there a problem with this code? If you could, please help be debug this code. Thank you for your time!

[Re-posted WHy does this happen? Js[^] — SA]

推荐答案

你完全忽略了我的回答:这是怎么回事? Js [ ^ ]。



你没有发表评论,没有问任何问题,你只是忽略了它。并复制了与之前问题相同的编程犯罪。但在你从一开始就修复它之前,没有什么可谈的。你的方法从一开始就是错误的,需要修复。



-SA
You totally ignored my answer: WHy does this happen? Js[^].

You did not comment it, did not ask anything, you just ignored it. And reproduced the same "programming crime" as it was in your previous question. But before you fix it from the very beginning, there is nothing to talk about. You approach is wrong from the very beginning and need to be fixed.

—SA


这篇关于JavaScript:帮助调试代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆