Steve problem :D


#1

Steve search wont work, can someone help

    var friends = {
        milena: {
            firstName: 'Milena',
            lastName: 'Petrovic',
            number:38169686209,
            address: ['Kraljevo', 'Dimitrija Tucovica 10/20', 'Serbia' ]
            },
        bill: {
            firstName: 'Bill',
            lastName: 'Mudonja',
            number: 03352645464,
            address: ['Kraljevo', 'Dimitrija Tucovica 105/20', 'Serbia' ]
            },
        steve: {
            firstName: 'Steve',
            lastName: 'Jobs',
            number: 032456565677,
            address: ['Kraljevo', 'Dimitrija Tucovica 10/20', 'Serbia' ]
            }  
    
    };
    
var list = function(friends) 
{
    for (var keys in friends)
    {    console.log(keys);
            };
};

var search = function (names)
     {
         for (var keys in friends)
                 {   
                     if (friends[keys].firstName === names)
                 {
                    console.log(friends[keys]);
                    return friends[keys];
                  }
            else {
            return "none"
                };
            };
     };
search("Milena");
search("Bill");

#2

Could you provide a link to the lesson?


#3

a function ends the moment a return keyword is reached. This currently happens in the first iteration of your loop, either the first entry is what you are looking for, or none is returned

You only want to return none after the loop has finished running

closing curly brackets (}) of if/else and for don't require semi-colons

@chesswithsean, sure: https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/7


#4

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