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 trialGavin Eyquem
Front End Web Development Techdegree Student 20,735 PointsI followed the code as instructed, it didnt work. Please help.
let html = '';
for (let i = 0; i < pets.length; i++){
let pet = pets[i];
html +=
<h2>${pet.name}</h2>
<h3>${pet.type} | ${pet.Breed}</h3>
<p>Age: ${pet.age}</p>
<img src="${pet.photo}" alt="${pet.Breed}">
;
// console.log(html); }
document.querySelector('main').insertAdjacentHTML('beforeend', html);
1 Answer
Steven Parker
231,269 PointsWhen posting code, always use Markdown formatting to preserve the code's appearance. Even better, make a snapshot of your workspace and post the link to it here as Reggie suggested.
It doesn't look like "pets" is defined. But if it really is and just isn't shown here, another issue is that commenting out the line that says // console.log(html); }
makes the code invalid because it causes the brace that ends the loop to be ignored.
The HTML portion of the code is also not shown here. For this code to work, it's important for the HTML to have a defined <main>
element.
Reggie Williams
Treehouse TeacherReggie Williams
Treehouse TeacherHey Gavin Eyquem do you have the snapshot of your workspace?