General Discussion Displaying the Content

Ryan King
Ryan King
5,068 Points

Whats 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
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi 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.