I have no idea why this happens?


#1


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


bill
steve
bob
{ firstName: 'Steve',
lastName: 'Gates',
number: '2450218',
address: [ 'batpark', 'blue county', 'lane 2' ] }
{ firstName: 'Steve',
lastName: 'Gates',
number: '2450218',
address: [ 'batpark', 'blue county', 'lane 2' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '2450217',
address: [ 'ballpark', 'red county', 'lane 1' ] }
ReferenceError: bill is not defined


var friends = {
    bill: {
        firstName : "Bill",
        lastName : "Gates",
        number : "2450217",
        address : ["ballpark","red county","lane 1"]
        },
    steve: {
        firstName : "Steve",
        lastName : "Gates",
        number : "2450218",
        address : ["batpark","blue county","lane 2"]
        },
    bob:{
        firstName : "Bob",
        lastName : "Gates",
        number : "2450219",
        address : ["basketpark","yellow county","lane 3"]
        }
    };
    var list = function(friends){
        for(var key in friends )
        console.log(key);
        };
var search = function(name){
    for(var dummy in friends){
        if(friends[dummy].firstName === name){
       console.log(friends[dummy]);
       return friends[dummy];
        }
        }
    
    };
    list(friends);
    search(bill);


#2

We need to pass a string, "Bill" to match the firstName value.

Do you call all your friends dummy or is this just a sign of immaturity?


#3

Ah I see, Thank you! and No, I dont call any of my friends dummy :smiley:


#4

Also why does steve gets printed twice? Why doesnt Bob get printed? Is there something wrong with my code?


#5

The lesson checker runs two tests on the search() function which both get logged by the function so we see extra output. It can be ignored. bob doesn't output because it is not searched for.


#6

Thank you. That was really helpful, I was really confused about the double print. Have a good day :smiley:


#7

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