Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jonathan Hamada
4,810 PointsConfused on how to access multiple objects in a variable.
Part II (Optional)
Now, given the following dictionary:
var users = { 'Students': [ {first_name: 'Michael', last_name : 'Jordan'}, {first_name : 'John', last_name : 'Rosales'}, {first_name : 'Mark', last_name : 'Guillen'}, {first_name : 'KB', last_name : 'Tonel'} ], 'Instructors': [ {first_name : 'Michael', last_name : 'Choi'}, {first_name : 'Martin', last_name : 'Puryear'} ] } Create a program that prints the following format (including the number of characters in each combined name):
Students 1 - MICHAEL JORDAN - 13 2 - JOHN ROSALES - 11 3 - MARK GUILLEN - 11 4 - KB TONEL - 7 Instructors 1 - MICHAEL CHOI - 11 2 - MARTIN PURYEAR - 13
Steven Parker
243,318 PointsInstructions for code formatting are in the Markdown Cheatsheet pop-up below the "Add an Answer" area.
1 Answer
Steven Parker
243,318 PointsIt's a bit like peeling an onion. Think in layers.
-
usersis the object itself -
users.Studentswould be the array of student objects -
users.Students[i]would be one student object (at index "i") -
users.Students[i].first_namewould be that student's name property
blake guyan
8,297 Pointsblake guyan
8,297 Pointslooks like a for loop to me
//this will give you access to the 2 objects const students = users.students const instructors = users.instructors
//iterate through the array and give you the values of the name length for (let i = 0; i < students.length; i += 1) { let name = students[i].first_name + " " + sudents.[i].last_name; let nameLength = name.length }) }
its not the whole solution but it should get you part of the way there :) i could also be wrong.. never rule that out!
for some reason the teehouse forum thing is messing with the formatting, i hope you can still read it