Contact List help please


#1

https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661#

I do not know why this code wont work, all it says is unexpected token. No semicolon or anything. Its blank after that. Please help.

<Look to the right of this box. That is how your post will look to everyone else.>
var search = function(name) {
    for(var key in friends) {
        if(friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
        }
    }
};
            
     var friends = {
john:{
firstName: "John",
lastName: "Gates",
number: "(76838991)",
address:["onehundred greed street", "suite 16", "rio starsen", "JO","765"]
};
steve:{

    firstName:"Steve",
    lastName: "Coins",
    number: "(67345764)",
      address:["onehundred groin street", "suite 16", "south st", "JO","765"]
    },

bill:{
    firstName: "Bill",
    lastname: "Seind",
    number: "(543265734)",
      address:["one street", "suite 16", "rio grande", "JO","765"]
    };
};
var list = function (){
for (var list in friends){
console.log(list);
    };
};


#2

Hi I noticed 2 problems :

1) in you definition of the variable friends, you mixed a little bit the colons and semicolons. The correct way to do it is

var friends = {
   john:{
      ...
   } ,        # <--- a colon here
steve:{
      ...
    },        # <--- a colon here, it was correct in your code
bill:{
      ...
    }         # <--- remove the semicolon
};

2) Then you should place the function search below the definition of friends because when search is defined, the variable friends is not defined yet (the variable friends is used in the function search).

I hope that it will help

Cheerio


#3

Thank you so much. This helped a lot. I've been stuck for a week


#4

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