Why is it listing three times?


#1


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


My code displayed the 'steve' object two times and the 'bill' object one time in the console output. I expected two outputs for 'steve' (one output from the console.log and another one from the return) and zero for 'bill' object.

Why does it show the 'bill' object? Any idea?

Thanks a bunch!

LN


var friends ={
    bill:{
        firstName:"Bill",
        lastName:"Joe",
        number:"123",
        address:["abc","def"]
    },
    
    steve:{
        firstName:"Steve",
        lastName:"King",
        number:"456",
        address:["hij","klm"]
    }
};

//var list = function(object){
//    for(var key in object){
//        console.log(key);    
//    };
//};
var a = 'Steve';
var search = function(a){
    for(var key in friends){
        if(a === friends[key].firstName){
            console.log(friends[key]);
            return friends[key];
        };
    };
}


#2

When we run the code, it logs out both the object inside the function, and then the return value (console behavior, not our code). Then the SCT runs the test for both Bill and Steve (if I recall) and those get logged as well. Nothing to fret over as long your output is as expected. You should still pass.


#3

I had this issue as well. I could pass but it still logged Bill once and Steve three times. I think its something to do with the return as well as the console.log being there plus the console on codecademy seems to log different things that jsbin for example. I don't fully understand it and I don't feel I quite got this one but I'm going to move on anyway as the output is essentially correct.


#4

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