Why doesn't this code work? Exercise 7


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']
    firstName: "Steve",
    lastName: "Jobs",
    number: "(66) 6666-6666",
    address: ['Apple', 'Silício']

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

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



Have a close look at



firstName: "Steve"


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


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


 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-( )

access via the square-bracket-notation

1 using the literal property-key


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"

in this case you will get the boolean VALUE of the married property
being false

would =display= "Hi, I work as a programmer"


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