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!

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 Displaying the Content

Homero Mendoza
Homero Mendoza
8,582 Points

Select.value is not displaying on the function generateImage

for some reason when displayed on the page the select.value doesnt display its just empty. someone know why?

const select = document.getElementById('breeds'); const card = document.querySelector('.card'); const form = document.querySelector('form');

// ------------------------------------------ // FETCH FUNCTIONS // ------------------------------------------ //fetch the img api fetch('https://dog.ceo/api/breeds/image/random') .then(response => response.json()) .then(data => generateImage(data.message))

//fetch the dog names fetch('https://dog.ceo/api/breeds/list') .then(response => response.json()) .then(data => generateOptions(data.message))

// ------------------------------------------ // HELPER FUNCTIONS // ------------------------------------------ function generateOptions(data){ const options = data.map(item => <option value ='${item}'>${item}</option> ); select.innerHTML = options; }

function generateImage(data){ const html= <img src ='${data}' alt> <p>Click to view images of ${select.value}s</p> ; card.innerHTML = html; }

// --------------------------

1 Answer

Steven Parker
Steven Parker
224,811 Points

The select list appears populated for me, but then I had to make a few assumptions about the code since it wasn't formatted for display.

When posting code, always use Markdown formatting to preserve the code's appearance and retain special symbols. An even better way to share code and make your issue easy to replicate is to make a snapshot of your workspace and post the link to it here.