Skip to content

Commit

Permalink
Merge pull request #181 from fredm23579/branch
Browse files Browse the repository at this point in the history
added some edits to HTML and JS
  • Loading branch information
fredm23579 authored Feb 14, 2024
2 parents c261686 + 1cfcb7e commit 9ffab56
Show file tree
Hide file tree
Showing 4 changed files with 511 additions and 76 deletions.
2 changes: 1 addition & 1 deletion assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ img {

#breed_image {
max-width: 50%;
text-align: left;
text-align: center;
}

/* Button Styling */
Expand Down
50 changes: 0 additions & 50 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,56 +45,6 @@ function togglePopup() {
}
}
//***************************************************************************************
const wikipedia_url = `https://api.thecatapi.com/v1/breeds`;
const Api_key = "live_lbUtmVrpjwLAoF4TTJuGlO7uGg9pNeaGaT3DcxOcHtR429cE9cxWVr7GdGiXauI6"
let StoredBreeds = []

fetch(url,{headers: {
'x-api-key': Api_key
}})
.then((response) => {
return response.json();
})
.then((data) => {

//filter to only include those with an `image` object
data = data.filter(img=> img.image?.url!=null)

StoredBreeds = data;

for (let i = 0; i < StoredBreeds.length; i++) {
const breed = StoredBreeds[i];
let option = document.createElement('option');

//skip any breeds that don't have an image
if(!breed.image)continue

//use the current array index
option.value = i;
option.innerHTML = `${breed.name}`;
document.getElementById('breed_selector').appendChild(option);

}
//show the first breed by default
showBreedImage(0)
})
.catch(function(error) {
console.log(error);
});

function showBreedImage(index)
{
document.getElementById("breed_image").src= StoredBreeds[index].image.url;

document.getElementById("breed_json").textContent= StoredBreeds[index].temperament


document.getElementById("wiki_link").href= StoredBreeds[index].wikipedia_url
document.getElementById("wiki_link").innerHTML= StoredBreeds[index].wikipedia_url
}




// Dog API Code //
const url = `https://api.thedogapi.com/v1/breeds`;
Expand Down
Loading

0 comments on commit 9ffab56

Please sign in to comment.