Search for a friend


My code prints out both Bills and Steves contact information even though I'm only calling Steve ): It worked until the search function so I'm guessing that's the problem, but I can't find it!

var friends = new Object();

friends.bill = {
    firstName: "Bill",
    lastName: "Billson",
    number: "12345",
    address: ['microsoft','USA','11333']

friends.steve = {
    firstName: "Steve",
    lastName: "Steveson",
    number: "6789",
    address: ['apple','USA','11444']

var list = function(friends) {
    for (var prop in friends) {

var search = function(name) {
    for (var prop in friends) {
        if (friends[prop].firstName === name) {
            return friends[prop];




bill and steve are both printed because you call your list function:


which list all your contact, search doesn't yield any result. search("steve"); won't be found, string comparison is case sensitive (steve vs Steve)

also, the exercise might output more because of exercise validation.

To see what your code truly outputs, you can run your code here


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