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

JavaScript

Steven Ventimiglia
Steven Ventimiglia
27,371 Points

Treehouse Badges API - How would I count the .length of "points" within a loop?

I created a loop that counts Badges and displays them. However, "points" seem like a different monster altogether.

Right now, I can do something like:

data.points['total']

...and it will give me the value.

But what if I wanted to loop through it like

data.points['html']
data.points['css']
data.points['js']

...etc., without defining which to display?

Plus the output seems to rely on me adding the title before the points.

Example:

"HTML: " + data.points['html'] 

Just like Go was added recently, it doesn't seem like this should remain as something I would have to manually update each time a new type of course is introduced.

Currently, any loops result as "undefined" with the points. Seems so fundamental, what am I missing here? lol

Reference: https://teamtreehouse.com/stevenventimiglia.json

1 Answer

Steven Ventimiglia
Steven Ventimiglia
27,371 Points

Bingo.

Time to stop my head from spinning. Will cleanup and style tomorrow. Thanks! ;)

https://codepen.io/StevenVentimiglia/pen/broMwX