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

General Discussion

Jeff Lange
Jeff Lange
8,788 Points

Help with Objects and Arrays Extra Credit

Intro to Programming EC project says:

"Try creating an object that represents you. Include all sorts of things about you, like your name as a string, and your favorite songs as an array. Explore how objects can be nested in other objects, and arrays."

I'm trying to make sure I actually took this far enough. Did I do the "nesting" they are referring to? Did I nest an object within an object? Should I have taken it further, or did I do what this assignment required? Code here (personal information changed for obvious reasons):

var myname = {
    first_name: "Jeff",
    middle_name: "M",
    last_name: "Google",
}
console.log(myname);

var looks = {
    hair: "brown",
    eyes: "blue",
    height: "5ft 10in",
    weight: "165lbs",
}
console.log(looks);

var fav_bible = ["Genesis", "Ruth", "Provebs", "Ecclesiastes", "Luke"]; 
    console.log(fav_bible);

var aboutme = [myname, looks, fav_bible];
    console.log(aboutme);

Thanks!

2 Answers

Paul Trimor
Paul Trimor
5,388 Points

A nested object within an object looks like this :

``` var looks = { ethnicity: "Asian", height: { centimeters: 169; inches: 69; words: "Five feet six inches" }, hair: "black", eyes: "pink"};

A nested array with an object looks like this: 

var Object = { ethnicity: "Asian", height: [169, 9, "five feet six inches"], hair: black; eyes: "pink" };

Jeff Lange
Jeff Lange
8,788 Points

Awesome! Thank you!

Marc Murray
Marc Murray
4,618 Points

Probably a little late to reply to this but when I use similar code to how you call the height array, I use an array called songs which the console says is not defined, would you have any idea what may be up with that?

Jeff Lange
Jeff Lange
8,788 Points

I'd have to see your code Marc. Can you post it here or in a new post?

Marc Murray
Marc Murray
4,618 Points

Managed to figure it out afterwards, thanks though!