8. Victory


  1. Victory!

    The code is only returning "Bill" for some reason instead of giving me the contact information. Please help on how I can get the rest of the information as well!

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "212",
        address: ["68","Wilkie Road","228070"]
    steve: {
        firstName: "Steve",
        lastName: "Plier",
        number: "313",
        address: ["53","Sophia Road","123456"]
    Jack: {
        firstName: "Jack",
        lastName: "Skellington",
        number: "111",
        address: ["11","XYZ Road","111111"]
    Rose: {
        firstName: "Rose",
        lastName: "Drownsnever",
        number: "222",
        address: ["22","Titanic Road","222222"]

var search = function (name) {for (var key in friends){if (friends[key].firstName === name ){console.log(friends[key])};return friends[key];}}

search: ("Bill")


Hi you should call your function search like that

seacrh("Here type the name ");


Yep, I tried that, but it returns only the the name in quotes, i.e. "Bill" if I type in search ("Bill").

I'm looking to get all the contact information, not just his name, I've changed my question as well. Would you know how to change the code to get the info?


Your serach statetment should be like that

var search = function (name) {
    for (var key in friends){
        if (friends[key].firstName === name ){
            return friends[key]

instead of

var search = function(name) {
  for (var key in friends) {
    if (friends[key].firstName === name) {
    return friends[key];

your return friends[key] should be inisde the if statement


It isn't changing anything..output is still the same


I think that @leonhard.wettengmx.n Could help you with that.



Please give us the FULL code you are using now....


you have no list function


You need to change keys name Jack and Rose to jack and rose. like:

jack: { }

rose: { }

Best of luck :slight_smile:


Check the first lesson, which tells all the code:

var friends = {};
friends.bill = {
  firstName: "Bill",
  lastName: "Gates",
  number: "(206) 555-5555",
  address: ['One Microsoft Way','Redmond','WA','98052']
friends.steve = {
  firstName: "Steve",
  lastName: "Jobs",
  number: "(408) 555-5555",
  address: ['1 Infinite Loop','Cupertino','CA','95014']

var list = function(obj) {
  for(var prop in obj) {

var search = function(name) {
  for(var prop in friends) {
    if(friends[prop].firstName === name) {
      return friends[prop];