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 JavaScript Objects Loop Through Objects Build an Object Challenge – One Solution

Images not showing in browser.

Hello!

So after a good while of trial and error, I can seem to get my images to display on the browser. I've tried changing the source to ../img/photo.jpg and css/img/photo.jpg but I cant seem to get it working correctly. The browser just displays the alt. I'm thinking it might be a Edge issue? Any ideas? Thank you!

const pets = [
  {
    name:'Bingo',
    type: 'Dog',
    breed:'Aussie',
    age: 2,
    photo: 'img/aussie.jpg' 
  },
  { 
    name: 'Patches',
    type: 'Cat',
    breed: 'Domestic Shorthair',
    age: 1,
    photo: 'img/tabby.jpg'
  },
  { 
    name: 'Pugsley',
    type: 'Dog',
    breed: 'Pug',
    age: 6,
    photo: 'img/pug.jpg'
  },
  { 
    name: 'Simba',
    type: 'Cat',
    breed: 'Persian',
    age: 5,
    photo: 'img/persian.jpg'
  },
  { 
    name: 'Comet',
    type: 'Dog',
    breed: 'Golden Retriever',
    age: 3,
    photo: 'img/golden.jpg'
  }
]; 


const main = document.querySelector('main');
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 scr="${pet.photo}" alt="${pet.breed}">
  `;
}

main.insertAdjacentHTML('beforeend', html);

1 Answer

<img scr="${pet.photo}" alt="${pet.breed}"> has src misspelled. You might also need to use url() around the path to the image.

Ahhhh. dang it! Thank you