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 trialRyan King
5,068 PointsWhats wrong???
i dont get the options or the name of the breeds below my image.
fetch('https://dog.ceo/api/breeds/list') .then(response => response.json) .then(data => generateOptions(data.message))
fetch('https://dog.ceo/api/breeds/image/random') .then(response => response.json()) .then(data => generateImage(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
Brandon White
Full Stack JavaScript Techdegree Graduate 34,662 PointsHi Ryan King,
The solution to your bug may be as simple as you’re attempting to use template literals without surrounding them in back tics. ` 👈🏾 This character needs to be placed before and after the following syntax: ${}.
Make that correction and things may work as you’re expecting them to. If not, I would question whether the argument you’re passing into the function is what you’re intending to pass into them. I don’t know because I don’t know the structure of the response being returned from the server. But , for instance, you’re calling map on the argument passed into the generateOptions, so that argument needs to be an array. So if the value of data.message isn’t an array, then your code may not function as intended. But again, that part may be perfect. Just wanted to add it as a potential option in case my first suggestion doesn’t act as a complete solution.