Don't get this


#1

var list = function (friends) {


}

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-55555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 666-6666",
address: ['One Apple Way','Greenmond','CA','14910']
},
};

I don't get anything in this lesson can someone pleas explain?


#2

What don't you understand? Have you skipped previous lessons?


#3

I meant i don't get the for/in loops sry i said that wrong


#5

yes i do understand for loops


#6

Do you know how a normal for loop works?

for (x=0; x<10; x++) {
// Do something
}

A for/in loop is the same as a for loop, it's just easier to write out. Here is an example of both doing the same thing.

var fridge = ['apple', 'milk', 'cow'];
for (x=0; x<fridge.length; x++) {
return fridge[x];
}

for( x in fridge) {
return fridge[x];
}

6. List em all - Not sure I understand this?
#7

so like this

var list = function (friends) {

}

for (var key in friends in list) {
console.log(friends);
}
var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-55555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 666-6666",
address: ['One Apple Way','Greenmond','CA','14910']
},
};


#8
var list = function (friends) {
}

Why is this function empty?

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

You can't call a variable before it's defined

Learn for/in loops Here


#9

@emgo_dev

thx for these examples. I had to change the return to console.log() to get it to display in the repl.it command window to visually see if what I thought it read would be the same in the output window.

var fridge = ['apple', 'milk', 'cow'];
for (x=0; xconsole.log(fridge[x]);
}

for( x in fridge) {
console.log(fridge[x]);
}

Output - Native Browser JavaScript

apple
milk
cow
apple
milk
cow

i have a better understanding of the for/in loop now after the simpler example you provide
which is appreciated because I completed this exercise and yet I remained confused. I am glad I see on here that am not the only person to struggle with this particular lesson.

I can go to my own post and add a note that my own query is resolved with a redirect a link to here so it may also possibly assist someone else if they get confused throughout this lesson too.


#10

@holycow28

glad u posted this as I thought I was the only one struggling to understand the lesson. I completed the unit but by the end of it was still confused so I knew that if I was confronted with this topic again I would probably just follow along and remain unclear on my understanding.

Thankfully this post a couple of other forum posts have indicated similar confusion on the lesson which have included helpful clarification by postings from other learners such as @emgo_dev so i feel a bit more confident now in proceeding to the next unit.