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

Jason Rich
seal-mask
.a{fill-rule:evenodd;}techdegree
Jason Rich
Front End Web Development Techdegree Student 10,048 Points

Just sharing my solution to Display an Array of Objects on the Page

I just wanted to add my version of a solution to the challenge.

Console.logging showed that I was getting each pet's profile values and placing them in their elements each loop but only the last pet's profile was displaying on the page.

I thought I needed to use .join or spread ... and was overthinking until it finally occurred to me that I simply needed to change profiles = to profiles += so that each loop would add and stack to the previous loop.

let profiles = '';

for (let i = 0; i < pets.length; i++) {
  profiles += ` 
  <h2>${pets[i].name}</h2>
  <h3>${pets[i].type} | ${pets[i].breed}</h3>
  <p>Age: ${pets[i].age}</p>
  <img src="${pets[i].photo}" alt="${pets[i].breed}"></img>
  `;
  document.querySelector('main').innerHTML = profiles;
}