Contact list task


#1

Task is The first function we'll create will be called list, and it will print out all the entries we have in our friends object. To do this, we'll want to use a bit of new syntax: a for/in loop.

It looks like this:

for (var key in object) {
  // Access that key's value
  // with object[key]
}

The "key" bit can be any placeholder name you like. It's sort of like when you put a placeholder parameter name in a function that takes arguments.

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

#2

so you called it key, then that is what you should log to the console using console.log? not list, the function, key is what will hold the objects (steve, bill) inside your friend object


#3

i did that it is still not working


#4

can i see an updated version of your full code?


#5

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


#6

if then change friends to object it won't work indeed. friends is what we call in programming an object, just like you have variable. Your object is called friends


#7

so where it says key in object I chnage that to key in friends


#8

yes, because your object is called friends. I wrote a detailed explanation here yesterday, you can read it if interessted


#9

var friends = {
bill: {
firstName : "Bill",
lastName : "Mahmood",
number : "07583303787",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {

     firstName : "Steve",
    lastName  : "Mahmood",
    number : "07583303787",
    address: ['One Cupertino Way','California','CA','95087']

    }

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

};

i did this but its still not working I done what you said


#10

parameter is what it is called (function parameters), your parameter should be called friends (like it was, it was fine)

You should really distinguish between words we use to describe something (parameter, object) and what we should actually use (friends, friends)


#11

i tried with friends and it still did not work


#12

your should close your friends object before your list function:

var friends = {
bill: {
firstName : "Bill",
lastName : "Mahmood",
number : "07583303787",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {

     firstName : "Steve",
    lastName  : "Mahmood",
    number : "07583303787",
    address: ['One Cupertino Way','California','CA','95087']

    }
} // this one, was at the end, rather then here
var list = function (friends){
for(var key in friends){
console.log(key);
}
}

see comment in code


#13

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