Search for a friend bugg?


#1

I'm not seeing my fault :frowning:

var friends = {
    bill:{
    firstName:"bill",
    lastName:"billson",
    number:"sqdfqsdf",
    address:["blabla"]
    },
    
    steve:{
    firstName:"Steve",
    lastName:"jack",
    number:"qsfsqd",
    address:["flafl"]
    }
  };

var list = function(friends){
    for(var key in friends)
    {
        console.log(key);
    }    
}

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

I get output of both names { firstName: 'bill', lastName: 'billson', number: 'sqdfqsdf', address: [ 'blabla' ] }
{ firstName: 'Steve', lastName: 'jack', number: 'qsfsqd', address: [ 'flafl' ] }
{ firstName: 'Steve', lastName: 'jack', number: 'qsfsqd', address: [ 'flafl' ] }
{"firstName":"bill","lastName":"billson","number":"sqdfqsdf","address":["blabla"]}


#2

Oops, try again. It looks like your search function doesn't return contact information for Bill.

If I run the code in the console of my browser it works fine.


#3

now it switched to steve O_O and I get the right output but not passing this course

`var friends = {
    bill:{
    firstName:"bill",
    lastName:"billson",
    number:"sqdfqsdf",
    address:["blabla"]
    },
    
    steve:{
    firstName:"steve",
    lastName:"jack",
    number:"qsfsqd",
    address:["flafl"]
    }
  };

var list = function(friends){
    for(var key in friends)
    {
        console.log(key);
    }    
}

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

Oops, try again. It looks like your search function doesn't return contact information for Steve.


#4

Hey @megaplayer21268 You have 2 problems :smile:

First in your most recent code you have gotten rid of the console.log add that line back in :smile:
Second capitalisation matters! It should be Bill and Steve. If you have problems like this again check those annoying capital letters!

P.S. As good practice add a few more semi colons in you're missing a few :smile: