5. Finding that Special Someone


#1

Getting an unexpected end of input error:

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])
}
}

var search = "Jones"


#2

Hi search is a function so this line

var search = "Jones"

should be the call function..


#3

Hi, I don't seem to remember what the difference between the two is.


#4

by doing this

var search = "Jones"

you created a variable search and stored in it "Jones" but the call function should be like that

search("Jones");

#5

YOU DIDNT CLOSED THE LAST CURLY BRACKET

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


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.