Can somebody please help me , i am not able to get this done. error ;Oops, try again. It looks like your search function doesn't return contact information for Steve


#1

var friends ={
bill:{firstName:"Bill", lastName:"gates",number:"(587) 716-1285",
address:["One Microsoft way","Redmond","WA","980520"] },
steve:{firstName:"Steve",lastName:"jobs", number :"(587) 713- 3211",
address:["Steve Jobs way", "Cupertino","CA","45250"]}
};

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

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

#2

@gonsalves

see if you remember when we have to use 2 time for loop 1st time we can take variable "i" (whichever you like.) and second time we use to take variable "x" (again whichever you like.), for eg:

for (var i in friends)
{if (friends[i].firstname === name)
{ console.log(friends[i]);
return friends[i];

"replace i with x"

and lastly you have to call the list as well as you have to print your contact list.... that is why it was showing you the error..

so

list (friends);
console.log(friends);

Hope this helps.


#3

Thank u so much for the reply but i am still getting the error. below is the code
var friends ={
bill:{firstName:"Bill", lastName:"gates",number:"(587) 716-1285",
address:["One Microsoft way","Redmond","WA","980520"] },
steve:{firstName:"Steve",lastName:"jobs", number :"(587) 713- 3211",
address:["Steve Jobs way", "Cupertino","CA","45250"]}
};

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

var search = function(name){
 for (var x in friends)
{if (friends[x].firstname === name)
{ console.log(friends[x]);
return friends[x];
}
}
};
list(friends);
console.log(friends);
error ;Oops, try again. It looks like your search function doesn't return contact information for Steve.

#4

hi gonsalves :grinning:,
your code is correct in general but not in details.

first: when you make the condition, if(friends[x].firstname === name)
be aware that you wrote ( .firstname) and not ( .firstName) the capital letter (N) is the problem.

second: remove console.log(friends) cause it'll only view the whole content of friends not just steve, wtite instead..... search("Steve") and be aware of (S) capital too to make the code run perfect.

i hope this help and i wish you a nice day