7. search for a friend


It doesn't return the information for Steve. But that's not even my problem, I don't understand the entire last paragraph, why do i need the friends[name].firstName and why do i need console.log and return

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "1234567890",
        address: ['Jones Street', 'Oakville', 'L6L 5W5', 'Canada']
        firstName: "Steve",
        lastName: "Jobs",
        number: "0987654321",
        address: ['Queen Street', 'Rosewood', 'Australia']
var list = function(friends) {
    for(var firstName in friends) {
var search = function(name) {
    for(var name in friends) {
        if (friends[name].firstName === name) {
            return friends[name];
        } else {
            return "No match!";


Update: I kind of understand it now but it still doesn't return Steve


what does kind of understand mean?

a function ends the moment a return keyword is reached, so return no match should be outside the for loop, otherwise no match is returned in the first iteration of the for loop


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