Steve and his contact info


#1


I'm honestly not sure where it's going wrong. It keeps saying that Steve's info isn't returning even though it is showing in the log. I even commented out console log to see if that was what I was viewing but Steve's info still returned in the window. HOWEVER....I don't see Bill's info.

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


Replace this line with your code.


#2

updated code. noticed a missing curly bracket.


#3

the url is the same for everyone, please copy paste your code to the forum


#4

var friends = {};
    friends.bill = {
        firstName: 'Bill',
        lastName: 'Bobbins',
        number: '404-234-5678',
        address: ["123 Sesame Street", "Bethlehem", "PA", "54673"],
        };
    friends.steve = {
        firstName: 'Steve',
        lastName: 'Stephanopolus',
        number: '678-987-6543',
        address: ["68 Dragon Lane", "Macon", "GA", "34982"],
        };
        
        var list = function(friends){
         for(var name in friends){
             console.log(friends[name]);
         };
        };
        
        var search = function(enterName){
          for(var name in friends){ 
            if (friends[name].firstName == enterName){
                console.log(friends[name]);
                return friends[name];
            }
                else{
                    return "No Match!";
                }
          }
            };

#5

a function ends the moment a return keyword is reached, this currently happens in the first iteration of your loop

place return no match outside the loop


#6

So I'm moving the entire else statement outside of the for loop? or just the return "No Match"?


#7

Nevermind! Got it thanks!!!


#8

you can do both, but you can just remove else and then return no match, saves code.


#9

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