6. List em' all - won't recognize "list" function


#1

I can't get passed the error: "Oops, try again. Did you create a function called list?"

I've tried various methods of creating a function called list, even ended up copied the syntax directly from the hint.

var friends = {
bill: {
firstName: "Bill",
lastName: "Whatever",
number: "666-666-6669",
address: ["111 Linny Dr.", "Philadelphia", "PA", "19144"]
},
steve: {
firstName: "Steve",
lastName: "Whoever",
number: "666-666-6668",
address: ["132 Blom Rd.", "Philadelphia", "PA", "19844"]
}
};

var list = function (friends) {
for (var key in object) {
console.log("Printing a string");
var myString = "Awesome!";
console.log(myString);
}
};


#2

Hi, I'm not sure whether you constructed this list function in this way intentionally, but you may want to read the command again - it should print keys of the friends array. That said, it should be bill and steve in your case.

About the function itself - review construction of the for loop. It should run through keys in... A type of object, yes, but should it refer to an undefined element called 'object'?


#3

The function I initially wrote was different. This is just copied and pasted from the hint because I can't get past the error "Oops, try again. Did you create a function called list?"

Whether or not the function works it should recognize there is a function called list, correct?


#4

I'm guessing the 'system' is not able to read the code word by word and see how did you match the expectations since it's only an automated machine. It just check the output and sometimes usage of specific method assuming the user follows instructions. I was in a similar situation several times here, just had to assume the error message is not 100% correct, fixed another thing (like comma or sth) and it worked. I know it isn't a very helpful reply, I'm just guessing how it works. Perhaps someone from moderation/staff here could comment more on it?


#5

This should clear your issue, the best reference to look at is right from the beginning of the lesson!

  1. The Parameter in the Function is friends
  2. The Variable in the for loop in this case can be firstName
  3. Then var firstName in will be friends
  4. Lastly, you will console.log the Variable in the for loop which is firstName

var friends = {
bill: {
firstName: 'Bill',
lastName: 'Gates',
number: '(414) 444-4444',
address: ['One Microsoft Way']
},
steve: {
firstName: 'Steve',
lastName: 'Jobs',
number: '(414) 555-5555',
address: ['Infinite Valley']
}
};

var list = function (friends) {
for (var firstName in object) {
console.log('Printing a string');
var myString = "Hey";
console.log(mystring);
}
};

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