5/6 ReferenceError: 'Jones' is not defined


#1

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"*/
var search = function (lastName) {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        if(lastName === contacts[i].lastName) {
            printPerson(contacts[i]);
        }
    }
};
search(Jones);

Is anyone able to assist with this? I am constantly getting an error stating that 'Jones' is not defined, but can't for the life of me find the issue (other threads on this don't seem to fix it either).

Thanks.


#2

Try using " " around Jones so it's:
search("Jones");


#3

search(Jones)

Do have a variable called Jones? No you didnt have one.

search("Jones");

This should work :smiley:


#4

facepalm been at this too long today. Thanks.


#5

search("Jones"); /* :P:P:P */


#6

use
search("Jones") :stuck_out_tongue:


#7

try this out : if(contacts[0].lastName === contacts[i].lastName){


#8

This Problem is solved.