7. Search for a friend


#1


It's me again. Struggling. I can't seem to get it to find Steve ? It doesn't find his name posts the stuff from the ELSE code and then eventually posts his details? Confused.


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


"Oops, try again. It looks like your search function doesn't return contact information for Steve."

Sorry friend not found!
steve
Sorry friend not found!
Sorry friend not found!
Sorry friend not found!
Sorry friend not found!
Sorry friend not found!
Sorry friend not found!
{"firstName":"steve","lastName":"jobs","number":"(0208) 234-1214","address":["Two Apple Way","Redmond","WA","8052"]}


var friends = {
 bill: {firstName: "bill",
 lastName:"gates",
  number: "(0208) 234-1214",
 address: ["One Microsoft Way","Redmond","WA","98052"]},
 steve: {firstName: "steve",
 lastName:"jobs",
 number: "(0208) 234-1214",
 address: ["Two Apple Way","Redmond","WA","8052"]}
};

var list = function(friends) {
 for (var firstName in friends) {
  console.log(firstName);   
 }
}


var search = function(name){
 
for (var firstName in friends){
 if(friends[firstName].firstName === name){
  console.log(friends[firstName]);
  return friends[firstName];
 }
         else {
             console.log("Sorry friend not found!");
             
         }
    
}

  
};

search("steve");


#2

Hi I changed steve to Steve with a capital S and it works. Must have been what the codeacademy task was looking for -_-
Case resolved lol


#3

That whole segment of code should be removed.


#4

Thanks :slight_smile: I did that eventually.


#5

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