Why doesn't this code work? Exercise 7


#1

Can somebody help me? I am trying to understand the final of this code, but it's confuse

var friends = {
    
    bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "(255) 5555-5555",
    address: ['Microsoft','Silício','Redmond']
        
        },
    steve:{
    firstName: "Steve",
    lastName: "Jobs",
    number: "(66) 6666-6666",
    address: ['Apple', 'Silício']
  }
    
};

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

var search = function (name){
    for (var contato in friends){
        if (friends[contato].firstname === name) {
            console.log(friends[contato]);
            return friends[contato];
        }
    }
};
search ("Steve");

#2

@netsurfer23635,

Have a close look at

friends[contato].firstname

and

firstName: "Steve"


#3

The name of variable... hahahaha, ok, thanks.


#4

@netsurfer23635
The correct comment would have been
i used the wrong literal property-key =firstName= in the dot-notation....

+++ contact list explained
object description
search as function
for-in loop explained
http://www.codecademy.com/forum_questions/54a616f9937676fb3d0024c7

============================================

 var james = {
    job: "programmer",
   married: false,
   sayJob: function() {
          // complete this method
          console.log("Hi, I work as a" + this.job);
    }
 };

Description of the james object.
The james object has 3 properties which are separated by a comma-,

there is a job property with property-key job and it's associated string value 'programmer'
there is a married property with property-key married and it's associated boolean value false
there is a sayJob property with property-key sayJob and it's associated anonymous function VALUE
( they also would 'say', the james-object has the sayJob()-Method )

access via dot-notation

(no variable allowed, only literal property-key-name )

james.job ==> you will get the associated string VALUE of the job property-key, thus
you get the string VALUE 'programmer'

james.married ==> you will get the associated boolean VALUE false

james.sayJob ==> you will get the associated anonymous function VALUE
to call/execute this method you add a pair of parenthesis-( )
james.sayJob();

access via the square-bracket-notation

1 using the literal property-key

james["job"]
james["married"]
james["sayJob"]()

2 using the property-key by reference (=== via a variable )

var propertyKey1 = "job";
var propertyKey2 = "married";
var propertyKey3 = "sayJob";
james[propertyKey1] ==> you will get the associated string VALUE of the job property-key, thus
you get the string "programmer"

james[propertyKey2]
in this case you will get the boolean VALUE of the married property
being false

james[propertyKey3]();
would =display= "Hi, I work as a programmer"


#5

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