Got the same output for 3. Displaying People but was told it was wrong


#1

Could anyone tell me why this was wrong


var printPerson = function(person) {
    console.log(contacts[person].firstName + " " + contacts[person].lastName)
}

printPerson(0)
printPerson(1)

while

var printPerson = function(person) {
    console.log(person.firstName + " " + person.lastName)
}

printPerson(contacts[0])
printPerson(contacts[1])

is right?


#2

because to verify the code is right, SCT (submission correctness test) will call the functions this way:

printPerson(contacts[0])
printPerson(contacts[1])

with this function:

var printPerson = function(person) {
    console.log(contacts[person].firstName + " " + contacts[person].lastName)
}

this will go wrong

yep, you can manipulate the function calls, but the exercise has certain expectations

Personally, i understand why the second approach is right. Its because of what will come later in this exercise, you will see


#3

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