Keep getting syntax error .. can't see it


Keep getting syntax error ... guys what I can't see ? Goal of this exercise is to get program to print out all users using a function and FOR loop.

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: ""

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: ""

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
function list() {
    var contactLength = contacts.length

    for (var i = 0, i < contactLength, i++) {


uhm.. this line:

for (var i = 0, i < contactLength, i++) {

i always separate the initialize, condition and increase from each other with semi-colons, not just comma's. Also, this line:


i is just a number:


So you might want to give it a thought what to do with i


Thank you mate. Appreciate your input !


did you resolve the issue?


Not yet. Still trying to crack it. But I'll figure it out. I always do eventually (after a few days) lol


i assume you did fix your for loop? Numbers are very useful to access items inside arrays (contacts)


Yeah commas are gone. I was being silly I guess. But now getting undefined ....


i is still just a number. add a console.log(i) inside your for loop to see this. printPerson expects an object, not a number.

uhm.. line 20, your function doesn't have a parameter (and doesn't require one) so you don't need a argument on line 27.


Code update:

Still don't like it. I'm getting green but I think I'm not supposed to have it 4 times. Gotta fix it.


still, line 28 just needs to be (without argument):


your function doesn't have a parameter:

function list(){//function content}

so no argument needed. Uhm.. i will hold the number? Why bother to write them manually? (line 24 and line 25)


Seems like I'm tip toeing around the bushes. Feel like it's almost right. Just not yet ... lol
I'm playing with array. I need to get the program print out all the content in an array "contacts"
I figured if I don't specify it like contacts[0] or [1] it will print out everything inside. I was wrong lol


why not simple use:


i will hold the numbers you need, since the condition is i < contactsLength, which is perfect, it will give the numbers required for as many people are in your contacts array


Maaan ... I feel so stupid right now ... I can see you saying "Dude just type the variable that holds the number from the FOR loop for crying out loud !"



But that would have been really rude to say. Always with this sort of thing, the moment you see it it makes perfect sense. I once spend 3 hours debugging a problem i had, guess what the problem was? I had a html element with a certain id, and i used the wrong id name in jquery to extract the value :open_mouth: it was tempting to throw the computer out of the window afterwards :stuck_out_tongue:


lmfao !

That's a good one mate ! Yeah I get those moments too. Makes you either throw a computer out off window or pull your hair off lol !

Well I better get used to it since yesterday I enrolled on uni to study software engineering. So I better suck it up and code on. :smiley:

Listen mate you've got my big thanks for sticking with me.

Greetings from London


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