5. Finding that someone special


#1

This error is driving me insane. Anybody care to help out??

SyntaxError: missing ) after argument list

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

@robertkooyman,

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

http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1


#3

I change it around and it still gives the same error:

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


#4

Can somebody help out? I am really stuck and do not have the solution.. @leonhard.wettengmx.n all my faith lies inyour hands :slight_smile:


#5

@robertkooyman,
Have you tried a resfresh Browser

++++ reset of session *****************
As you are manipulating with objects
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#8

@robertkooyman
Try this (copy and paste it in the code section)

function search(lastName)
{
var contactsLength = contacts.length;

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


#9
function search(lastName) {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
		if (lastName === contacts[i].lastName) {
		    printPerson(contacts[i]);
		}
		else {
		    console.log("No contact found");
		};
	}
};

search("Jones");`

#10

not sure if you already found the answer but here you go!


#11

just needed to add the else statement.. silly mistake can cost a lot of time get wasted.