6. We made a friend. A rather different code that works


#1

This line of code works. However, as I checked the forums, my code is rather different for 6. "We made a new friend".
Can someone tell me if my code is alright or is it just because I'm lucky that the course accepts it?

Replace this line with your code. 
var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

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

function list() {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        printPerson(contacts[i]);
    }
}
list()

var add = function(firstName,lastName,email,phoneNumber){
    this.firstName=firstName;
    this.lastName=lastName;
    this.email=email;
    this.phoneNumber=phoneNumber;
    contacts[contacts.length]=this;
}
add("Bob","David","xiaosaber3943@live.com.sg","942349032")
list()


#2

Your code looks fine to me. If Codecademy accepts it, then it gave the desired result, and you shouldn't need to worry about it. Your code won't always be the same as what's posted on the forums, and that's fine. Good luck. :slight_smile:


#3

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