Make a beautiful contact search


#1



My code returns me a ugly view of the contact data, and it also returns the if and the else action. I dont understand it.
Please help me make a nice view of the contact searcher.


var friends = {
	bill: {
		firstName: "Bill",
		lastName: "Gates",
		number: "(206) 555-5555",
		address: ['Chiavari', '3088', 'Montevideo']
	},
	steve: {
		firstName: "Steve",
		lastName: "Jobs",
		number: "405 41155",
		address: ['Rivera', '2051', 'Montevideo']
	}
};



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

var search = function(name) {
    for(var x in friends) {
      if(friends[x].firstName === name) {
        console.log(friends[x]);
      } else {
        console.log("No se ha encontrado nada");
      }
    }
}

search("Steve");


#2

The else clause is neither asked for nor needed. Had a not found message been asked for, we would have been instructed to write it after the for loop.

... = function (name) {
    for ( ... ) {
        if ( ... ) {

        }
    }
    console.log("Not found");
};

Here is a topic that has a couple of examples. There are others, as well. Dig around in this forum.

https://discuss.codecademy.com/t/8-victory-contact-list/60009


#3

Thank you very much mtf!! Im diggin around!


#4

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