I need help! I can't make it print the right thing


#1

So I coded this:
var friends = {
bill:{
firstName: "Bill",
lastName: "Gates",
number: "819-777-4536",
address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
},
steve:{
firstName: "Steve",
lastName: "Jobs",
number: "819-564-8923",
address: ['two Apple Rd', 'San-Diego', 'CA', '45873']
}
}

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

search("Steve");

but when it prints it out to the console, it prints this:
{ firstName: 'Steve',
lastName: 'Jobs',
number: '819-564-8923',
address: [ 'two Apple Rd', 'San-Diego', 'CA', '45873' ] }
{"firstName":"Steve","lastName":"Jobs","number":"819-564-8923","address":["two Apple Rd","San-Diego","CA","45873"]}

How do I make it only print the info on the person once?


#2

@tagcoder45513,
++++ why second display of last Item
+++++++++++++++++++++++++++++
It is the Javascript interpreter which is running in this course-environment,
it display's the last non-displayed action...

You will also encounter this, when you are doing a return-statement
as last action...
You could counter this by using a
console.log( " " ); as last statement....

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );


#3

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