3.) Displaying People Unexpected Token?


#1

So I get an unexpected token error yet it does not give any character or symbol to look at so I do not know if I have set something up wrong or I have a simple grammatical 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];

var printPerson = function(person);
console.log(person.firstName + " " + person.lastName);
console.log(printPerson[0]);
console.log(printPerson[1]);


#2

If you don't know where the syntax error is you can use a linter, for example jslint.

Expected '{' and instead saw ';'.
var printPerson = function(person);


#3

facepalm ah thank you for the link and answer! :smiley:


#4

However, now it says Oops, try again. It looks like your function didn't log "Bob Jones" to the console. Did you remember to call your function on bob? Apparently my console.logs at the end are not working out...

var contacts = [bob, mary];

var printPerson = function(person) {
console.log(person.firstName + " " + person.lastName); }
console.log(printPerson[0]);
console.log(printPerson[1]);

#5

Not sure if this is the correct way to procede with the code but I passed the lesson with this below

var contacts = [bob, mary];

var printPerson = function(person) {
console.log(person.firstName + " " + person.lastName); }
var personArray = ["Bob Jones", "Mary Johnson"]
console.log(personArray[0]);
console.log(personArray[1]);

#6

This is definitely not the correct way :slight_smile: Let's talk about your previous code:

var contacts = [bob, mary];

var printPerson = function(person) {
console.log(person.firstName + " " + person.lastName); }
console.log(printPerson[0]);
console.log(printPerson[1]);

The function is correct, problem is in the two last lines. You were asked to use this function to print out information about people in the contacts array. We don't need console.log statements, we just need to call our function and pass contacts[0] and contacts[1] as a parameter:

printPerson(contacts[0]);
printPerson(contacts[1]);

#7

Ah. Thank you very much! I understand now and will precede to fix my code xD


#8

You're very welcome :slight_smile:


#9

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