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

Ilija Marinkovic
Ilija Marinkovic
6,456 Points

This is my solution for this video

/*
  Create an array of 'pet' objects.
  Each object should have the following properties: 
  name, type, breed, age, and photo
*/

let html = ''

const pets = [
  { 
    name: "Maria", 
    type: "Dog", 
    breed: "Australian Shepherd", 
    gender: "Female",
    photo: "img/aussie.jpg"
  },

  { 
    name: "Cassie", 
    type: "Dog", 
    breed: "Dachshurd", 
    gender: "Female",
    photo: "img/dachshund.jpg"
  },

  { 
    name: "Goldie", 
    type: "Dog", 
    breed: "Golden Retriever", 
    gender: "Male",
    photo: "img/golden.jpg"
  },

  { 
    name: "Sprinkles", 
    type: "Cat", 
    breed: "Persian Cat", 
    gender: "Female",
    photo: "img/persian.jpg"
  },

  { 
    name: "Tubby", 
    type: "Dog", 
    breed: "Pug", 
    gender: "Male",
    photo: "img/pug.jpg"
  },

  { 
    name: "Lazy", 
    type: "Cat", 
    breed: "Tabby Cat", 
    gender: "Male",
    photo: "img/tabby.jpg"
  }
]

function createPetList(arr) {
  let petList = ''

for (let i = 0; i < arr.length; i++ ) {
  petList += `
  <h2>${arr[i]['name']}</h2>
  <h3>${arr[i]['type']} | ${arr[i]['breed']}</h3>
  <p>${arr[i]['gender']}</p>
  <img src="${arr[i]['photo']}" alt="${arr[i]['breed']}">
  `
  }
  return petList
}

document.querySelector('main').innerHTML = createPetList(pets)