function list() {
var contactsLength = 2;
for (i = 0; i < 3; i++) {
console.log(printPerson);
}
console.log(list)
}
This was my first attempt to this one and this is what I wrote, I was surprised that it said I passed but then I looked at the console and this is what it wrote:
Bob Jones
Mary Johnson
[Function: printPerson]
[Function: printPerson]
[Function: printPerson]
[Function: list]
this looked very strange to me and I’m not sure if I did it wrong…
Hello!
I have a question for smart people
explain me, why code academy asks me to do this:
“At the start of the function, define a variable to store the number of items in the contacts array. Call it contactsLength”.
why we need this var here?
maybe it could work without contactsLength?
function list () {
for (i = 0; i < contacts.length; ++i) {
printPerson(contacts[i])
}
}
function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
};
};
The reason they ask us to define the variable is they want us to use it in the for loop instead of the .length method. We just use contactsLength instead.