7. Why is Bill's information displayed with Steve's?


#1


I'm not stuck, just wondering about the output, as I don't under stand it.



This is the output of my code:
{ firstName: 'Steve',
lastName: 'Steven',
number: '(173) 238 9010',
address: [ 'Someother place', 'sometime', 'NB', '12480' ] }
{ firstName: 'Steve',
lastName: 'Steven',
number: '(173) 238 9010',
address: [ 'Someother place', 'sometime', 'NB', '12480' ] }
{ firstName: 'Steve',
lastName: 'Steven',
number: '(173) 238 9010',
address: [ 'Someother place', 'sometime', 'NB', '12480' ] }
{ firstName: 'Bill',
lastName: 'Billy',
number: '(506) 755 7213',
address: [ 'One place', 'somewhere', 'WA', '1492' ] }
{"firstName":"Steve","lastName":"Steven","number":"(173) 238 9010","address":["Someother place","sometime","NB","12480"]}
Here is my code:

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Billy",
        number: "(506) 755 7213",
        address: ["One place","somewhere","WA","1492"]
        },
    steve: {
        firstName: "Steve",
        lastName: "Steven",
        number: "(173) 238 9010",
        address: ["Someother place","sometime","NB","12480"]
        }
};
var list = function (friends) {
    for(var key in friends) {
        console.log(key);
    }
};
var name = ["Bill","Steve"];
var search = function(name) {
    for(var key in friends) {
        if(friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
        };
    };
};
search("Steve");

So I was wondering, why is Bill's information displayed as well??

Thanks.


#2

the exercise validates your code works correctly, this is doing by calling the functions. The result of these function calls will show in the console, as you have experienced

Nothing to worry about


#3

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