I am stuck at this topic,"It looks like your search function doesn't return contact information for Steve"


#1


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.

var friends= new Object();
friends.bill=new Object();
friends.bill.firstName="Bill";
friends.bill.lastName="Gates";
friends.bill.number=12345678;
friends.bill.address=["Microsoft","USA"];
friends.steve=new Object();
friends.steve.firstName="steve";
friends.steve.lastName="Jobs";
friends.steve.number=87456123;
friends.steve.address=["apple","USA"];

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

list(friends)

var search= function(name){
    for(var keys in friends){
        if(friends[keys].firstName=== name){
            console.log(friends[keys]);
            return friends[keys];
        }
    }
}

search(steve)


#2

These should be strings, not numbers. Phone numbers are typically written,

555-555-1212

The dashes are not valid in number form, so,

... .number = "555-555-1212";

#3

hi,
i have changed the number to string, it still shows cant return contact information for Steve


#4

here..
friends.steve.firstName="steve";
Conventionally names are written this way

Steve Jobs

Their first letters are uppercased!
You need to make some changes in the string value 'steve'


#5

can i ask what's the point of use return, why not just use console.log to print out the search result?


#6

Console.log() is used to show the o/p on the screen.
Just returning the values will not show the o/p on the screen.
(even you may see that names or information are printed twice,Actually its done by CC interpreter)


#7

It's impossible to know what the author had in mind, other than to cause this question to keep surfacing. Being as it's a lesson, and not real-world code with an objective, it is likely just for the practice, and so we could see the output without having to log the return value.

Normally, a utility function does not log anything, only return a result. The return value is then evaluated and logged accordingly. Returned data may also be stored, either in local data structure or in a data base on the server.


#9

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