7. Search for a friend -- I have two questions about the printed results


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661


I was able to get through this lesson but the way my code prints seems pretty off. For instance, Steve is printed twice, and the brackets surround each object. Is that supposed to happen? Here's my code.


var friends = {
    bill: {
        firstName: "Bill",
        lastName: "x",
        number: 1,
        address: ['1314 Blueberry Street', 'Middle School Ave', '10456']
    }  ,
    steve: {
        firstName: "Steve",
        lastName: "hobbes",
        number: 2,
        address: ['666','5th avenue', 'New York', 'NY']
        }
    };
    
    /*var list = function(friends) {
        for (var friends in friends) {
            console.log(friends);
        }
    }*/
    
    var search = function(name) {
        for(var key in friends) {
            if(name === friends[key].firstName) {
                console.log(friends[key]);
                return friends[key];
            }
        }
    };

and here are the results:

{ firstName: 'Steve',
  lastName: 'hobbes',
  number: 2,
  address: [ '666', '5th avenue', 'New York', 'NY' ] }
{ firstName: 'Steve',
  lastName: 'hobbes',
  number: 2,
  address: [ '666', '5th avenue', 'New York', 'NY' ] }
{ firstName: 'Bill',
  lastName: 'x',
  number: 1,
  address: [ '1314 Blueberry Street', 'Middle School Ave', '10456' ] }


#2

I have had the same thing happen to me on a lot of lessons. I think that it is on purpose, but I'm not sure why.


#3

I'm having the exact same problem. Weird. When you return it, though, I think it prints it.


#4

It's possible that it's a bug.


#6

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