7/8 Code is passing, but I'm not getting the results I want


#1

Hi,

My code in 7/8 passes, but I'm not getting the expected result. It's supposed to return Richard Branson's details, but I'm getting an Bill Gates' instead. Hope you can help me out!

Code
var friends = {};

friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "111-111",
address: ['Washington', 'USA']};

friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "222-222",
address: ['Cupertino', 'USA']};

friends.richard = {
firstName: "Richard",
lastName: "Branson",
number: "333-333",
address: ['Necker Island', 'Pacific Ocean']};

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

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

};

list();
search("Richard");

Console:
bill
steve
richard
{ firstName: 'Bill',
lastName: 'Gates',
number: '111-111',
address: [ 'Washington', 'USA' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '111-111',
address: [ 'Washington', 'USA' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '111-111',
address: [ 'Washington', 'USA' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '111-111',
address: [ 'Washington', 'USA' ] }
{"firstName":"Bill","lastName":"Gates","number":"111-111","address":["Washington","USA"]}


#2

should read,

if (name === friends[key].firstName) {

Expect extra output due to SCT, so long as you see the output you expect. You can comment the list() function call for this exercise so it doesn't output.


#3

Worked like a charm. Thanks @mtf!


#4