VICTORY! Contact list, Lesson 8


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/8?curriculum_id=506324b3a7dffd00020bf661


I'm just wondering if someone can explain how to answer the question when the prompt asks; "How might you format the output to look like this?


First Name: Steve
Last Name: Jobs
Number: (408) 555-5555
Address: 1 Infinite Loop
         Cupertino, CA 95014


#2

what code do you have so far? I can help you, but wasn't planning to program everything for you


#3

I've moved on to the next lessons at this point after trying my hand at it with no avail. Granted I didn't try for very long because I would like to finish the course! This is what I tried to do however I would get undefined values. What I tried to do was change the function:

var search = function(name) {
    for (var entry in friends) {
        if (friends[entry].firstName === name) {
            console.log("First Name: " + friends[firstName])
            console.log("Last Name: " + friends[lastName])
            console.log("Number: " + friends[number])
            console.log("Address: " + friends[address])
        }
    }
}

#4

I knew there had to be a more efficient way of doing this but my knowledge of Javascrip is limited but growing at this point so I thought I could learn the concept later on in the course or in a different couse.


#5

At this point I've tried different variations because I can't understand why I'm getting undefined values.

"First Name: " + friends.firstName

"First Name: " + friends.name.firstName

"First Name: " + friends[firstName]

#6

Hello @awshin,

Can you put your full code as you're almost at end of this section, It will be easy to debug if you put your complete code here ?


#7

here:

if (friends[entry].firstName

you do it right, you want the firstName of your current friend/entry, so if you then want to log the first name you get:

console.log("First Name: " + friends[entry].firstName)

we have friends object, which contain two more objects (bill and steve, represented as entry with help for in loop), and then bill and steve have firstName, lastName and so on property


#8

Thank you very much! upon finishing the section about objects I was also able to get different solutions to my problem! Thank you again very very much for all your help :smiley:


#9

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