Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
This video covers one solution to Part One the "Build an Object" challenge, and demonstrates one approach to structuring this data. It then introduces the instructions for Part Two: Rendering the pet information in the browser!
How did you do? Don't worry if you weren't able to complete part one of the challenge - learning how to work with objects takes time and practice! In this video, we'll explore one potential approach to structuring your array of pet objects!
Part One - Example Solution
If you want a fresh start for part two of the challenge, you can copy the solution used in the video from the snippet below:
Array of pet objects:
const pets = [
{
name: 'Joey',
type: 'Dog',
breed: 'Australian Shepherd',
age: 8,
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'
}
];
Part Two - Creating a Data Structure
For the next step in the challenge, we'll really step things up a notch! We'll work on implementing a for loop to iterate over each object in the pets array and develop a solution for making this information display in the browser. This is a really challenging task, so try your best - and don't worry if you need to step ahead to see an example of just one valid solution!
Your workspace contains an example of the HTML you'll display for each pet, but you can also copy the snippet below:
<h2>Joey</h2>
<h3>Dog | Australian Shepherd</h3>
<p>Age: 8</p>
<img src="img/aussie.jpg" alt="Australian Shepherd">
We've also included some useful learning resources below to help you if you're feeling stuck, or just need a refresher! Remember, there are multiple ways to add or display HTML in the browser, so you may want to practice multiple approaches!
Terms
- for statement / for loop - an iteration statement that allows you to repeat a code statement until a specified condition is met.
Resources
- Accessing array elements - MDN
- for statement / for loop - MDN
- Template literals - MDN
- Working with objects - MDN
Inserting new HTML onto the page
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up