Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Done #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

170 changes: 169 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,169 @@
console.log('%c HI', 'color: firebrick')


// document.addEventListener("DOMContentLoaded", function(){


// fetch('https://dog.ceo/api/breeds/list/all')
// .then((response) => response.json())
// .then((json) => {
// console.log(json.message)
// let breeds = Object.keys(json.message)
// addBreeds(breeds)
// })

// fetch("https://dog.ceo/api/breeds/image/random/4")
// .then((response) => response.json())
// .then((json) => {
// let dogs = json.message
// addDogs(dogs)
// })


// function addDogs(dogs) {
// let container = document.getElementById('dog-image-container')
// for (let dog of dogs) {
// console.log(dog)
// let div = document.createElement('div')
// let image = document.createElement('img')
// image.src = dog
// div.appendChild(image)
// container.appendChild(div)
// }
// }

// function addBreeds(breeds) {


// for (let breed of breeds) {
// let ul = document.getElementById('dog-breeds')
// let li = document.createElement('li')
// li.addEventListener('click', () => { li.style.color = 'red'})
// li.innerHTML = breed
// ul.appendChild(li)
// }
// }

// })


// function breedFilter() {
// let drop = document.getElementById('breed-dropdown')
// let value = drop.value

// if (value == "a") {
// let newbreeds = breeds.find((breed) => breed.charAt(0) == "a")
// } else if (value == "b") {
// let newbreeds = breeds.find((breed) => breed.charAt(0) == "b")
// } else if (value == "c") {
// let newbreeds = breeds.find((breed) => breed.charAt(0) == "c")
// } else if (value == "d") {
// let newbreeds = breeds.find((breed) => breed.charAt(0) == "d")
// } else {
// let newbreeds = breeds
// }
// return newbreeds
// }










document.addEventListener("DOMContentLoaded", function(){

fetch("https://dog.ceo/api/breeds/image/random/4")
.then(function(response){
return response.json()
})
.then(function(json){
console.log(json)
let dogs = json.message
dogsondom(dogs)
})

function dogsondom(dogs) {
const ul = document.getElementById("dog-image-container")
for (const dog of dogs) {

let image = document.createElement("img")
image.src = dog
ul.appendChild(image)
}
}

fetch('https://dog.ceo/api/breeds/list/all')
.then(function(response){
return response.json()
})
.then(function(json){
//console.log(json)
let breeds = json.message
let breed = Object.keys(breeds)
breedsondom(breed)
})


function breedsondom(breed) {
const ulTwo = document.getElementById("dog-breeds")
for(const pup of breed){
let liTwo = document.createElement("li")
liTwo.innerHTML = pup
ulTwo.appendChild(liTwo)
liTwo.addEventListener("click", function(e){
console.log(e)
e.target.style.color = "blue"
})
}
filterbreeds(breed)
}

function filterbreeds(breed) {
let selector = document.getElementById("breed-dropdown")
selector.addEventListener("change", function(e){
let values = e.target.value

switch (values) {
case values = "a":
let breedtwo = breed.filter(dog => dog.charAt(0) == "a")
filter(breedtwo)
break
case values = "b":
let breedthree = breed.filter(dog => dog.charAt(0) == "b")
filter(breedthree)
break
case values = "c":
let breedfour = breed.filter(dog => dog.charAt(0) == "c")
filter(breedfour)
break
case values = "d":
let breedfive = breed.filter(dog => dog.charAt(0) == "d")
filter(breedfive)
break
}

})
}
function filter(array) {
console.log(array)
const list = document.getElementById("dog-breeds")
list.innerHTML = ""
for (const element of array) {
let listitem = document.createElement("li")
listitem.innerHTML = element
list.appendChild(listitem)
}
}

})