5/6 Adress Book: Why is this wrong?


#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];

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[i].lastName === lastName) {
printPerson(contacts[i]);
}
};

search("Jones")


#2

Hi, foor-lopp needs {} :

for (var i = 0; i < contactsLength; i++) {
if (contacts[i].lastName === lastName) {
printPerson(contacts[i]);
}
}


#3

yeah right. for loops needs brackets { }


#4

can anyone spot a problem with my code i cant work it out

print("welcome to your personal adresss book")
homepage=input("if you would like to add a new adress key \nn\nif you would like to view your adresses key\nv")

def details():
name = input("please enter the persons name")
adress = input("please enter the persons adress")
print("thankyou",name,"'s adress has been created")
info = (name +""+ adress)
add_to_database(info)

def add_to_database(info):
temp1 = open("address book.txt","r")
temp1.write(info)
temp1.write("\n")

if homepage== "n":
details()
if homepage== "v":
search()