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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Swan The Human](https://uploads.teamtreehouse.com/production/profile-photos/10094022/micro_profile_pic.jpg)
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 PointsDoggo Select. The images come up upon selecting the breed type but the image doesn't change when i click on it.
Ive checked the code up and down in comparison to the one in the video. I figured it was something to do with the event listener but it isn't any different then it is in the videos. Also i was wondering if it had to do with the fact that in the api url it says "breeds" but in the fetchBreedImage it doesn't but when i change one or the other the link is broken
const select = document.getElementById('breeds');
const card = document.querySelector('.card');
const form = document.querySelector('form');
// ------------------------------------------
// FETCH FUNCTIONS
// ------------------------------------------
function fetchData(url){
return fetch(url)
.then(res => res.json())
};
fetchData('https://dog.ceo/api/breeds/list')
.then (data => generateOptions(data.message))
fetchData('https://dog.ceo/api/breeds/image/random')
.then ( data => generateImage(data.message))
// ------------------------------------------
// HELPER FUNCTIONS
// ------------------------------------------
function generateOptions(data){
const options = data.map( item => `
<option value='${item}'>${item}</option>
`).join('');
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;
}
function fetchBreedImage(){
const breed = select.value;
const img = card.querySelector('img');
const p = card.querySelector('p');
fetchData(`https://dog.ceo/api/breed/${breed}/images/random`)
.then(data => {
img.src = data.message;
img.alt = breed;
p.textContent = `Click to view more ${breed}s`
})
}
// ------------------------------------------
// EVENT LISTENERS
// ------------------------------------------
select.addEventListener('change', fetchBreedImage);
card.addEventListener('change', fetchBreedImage);
// ------------------------------------------
// POST DATA
// ------------------------------------------
1 Answer
![KRIS NIKOLAISEN](https://secure.gravatar.com/avatar/65d74a723997b41a80d2d909c6e06960?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
KRIS NIKOLAISEN
54,969 PointsThe message states "Click to view more" so you will want to handle the click event.
You have:
card.addEventListener('change', fetchBreedImage);
It should be:
card.addEventListener('click', fetchBreedImage);
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 PointsSwan The Human
Full Stack JavaScript Techdegree Student 19,338 Pointsoh wow that was fairly dumb of me haha. I knew it had to be something stupid. Been staring into the depths for too long. Much appreciated friend!