'7. Search for a Friend' Code is accepted, but doesn't seem correct


#1



7. Search for a friend


This code is accepted, but I don't understand (1) Why its printing Steve twice (2) why it's printing at all since I didn't call the search function ( search('Bill'); or search ('Steve'); ).....

var friends = {
    bill: {firstName: 'Bill',
          lastName: 'Truelove',
          number: '398 898 8765',
          address: ['53 Creekside Drive, Jackson, WY']
          },
          
    
    
    steve: {firstName: 'Steve',
           lastName: 'Sanders',
           number: '662 123 4567',
           address: ['123 Montgomery Street, Starkville, MS']
           }
    };
    
    var list = function(){
        for(var firstName in friends){
            console.log(firstName);}
        };
        
        list();
        
    var search = function(name){
            for(var prop in friends){
                if(friends[prop].firstName === name){
                    console.log(friends[prop]);
                    return friends[prop]
                    
                    
                    };
                };
        };


#2

@bartonyoung,

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

As proof to the assumption you could use

list();
search("Steve");
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

#3

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