Need help on 7/8


#1

Hi I'm having trouble getting the code to return the information for both men, at the moment I am just getting steve job's information.

var friends = {}; {
var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(707) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
}
};
var friends = {
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(707) 555-5566",
address: ['90210','Hollywood','CA','95688']
}
};
};

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


#2

The Basics:
An object has one or more properties separated by a comma-,
Each property consists of a property-key and it's associated value

var friends ={ name: 'shantanu' , contact:'9557711991' };
The friends object has 2 properties:
1. a name property with property-key name and a string value 'shantanu'
2. a contact property with property-key contact
and a string value '9557711991'

You can either create an object using the literal notation as was done
defining the object friends.

OR

You create an object using the constructor notation.
first you create an empty Object using the following syntax
either with
var friends = new Object();
OR
var friends = {};
THEN
you add the properties by using the following syntax
friends.name = 'shantanu';
friends.contact = '9557711991';
THUS

var friends = {};
friends.name = 'shantanu';
friends.contact = '9557711991' ;
console.log( friends );

will give output:

{ name: 'shantanu', contact: '9557711991' }

You should also familiarize yourself with following syntax
In the constructor notation you can
add a property
EITHER
the object-name dot literal property-key equal-sign associated value
friends.email = "alex@codecademy" ;
OR
the object-name squarebracket-open the property-key as string literal squarebracket-close equal-sign associated value
friends["email"] = "alex@codecademy" ;
OR
using variables

var thePropertyKey = "email";
var theAssociatedValue = "alex@codecademy.com";
friends[thePropertyKey] = theAssociatedValue;
console.log( friends );

will give the output:

{ name: 'shantanu', contact: '9557711991', email: 'alex@codecademy.com' }

#3

Look here for an explanation
object
function
for-in-loop
list-function
search-function
http://www.codecademy.com/forum_questions/545275fd8c1ccc8e3e000a23#comment-5457b12c9c4e9d87cb00003f


#4

Thank you fr your help and for directing me towards that information! It helped me a great deal! One more thing though, why does the function return the array for steve twice?

var friends = {

bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way, Redmond, WA']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 555-5556",
address: ['Beverly Hills, CA, 90210']
}
};

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

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

From that I get:
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(206) 555-5556',
address: [ 'Beverly Hills, CA, 90210' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(206) 555-5556',
address: [ 'Beverly Hills, CA, 90210' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '(206) 555-5555',
address: [ 'One Microsoft Way, Redmond, WA' ] }


#5

Add an extra code line at the End-of-your-code
console.log( "==This is my End==" );

You will see that you have an extra output AFTER your code is excuted
as the course-checker will do it's Display as well