From 69858110d237b5feeeef4f16a48621f402104563 Mon Sep 17 00:00:00 2001 From: ValtierraXavier Date: Wed, 7 Dec 2022 17:30:35 -0500 Subject: [PATCH 1/3] Complete random_cat_api. Work on bonus --- lib/script.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/script.js b/lib/script.js index e69de29..8497fb1 100644 --- a/lib/script.js +++ b/lib/script.js @@ -0,0 +1,17 @@ +const url = 'https://api.thecatapi.com/v1/images/search?api_key=e6f2adcdc125aef38c14ca0be4465d6a75b789e6.rtfd'; +const randButton = document.getElementById('randomButton'); + +randButton.addEventListener('click', randomCat); + + +function randomCat () { +fetch(url) +.then (res=>res.json()) +.then( res => displayCat(res[0].url)) +.catch(err => console.log('unsuccessful', err)); +} + +function displayCat(imgurl){ + console.log(typeof(imgurl[0].url)); + document.getElementById('randomCatImage').src=imgurl; +} \ No newline at end of file From ae9834846168ffedc3bfdbf975238ac872aa02f4 Mon Sep 17 00:00:00 2001 From: ValtierraXavier Date: Wed, 7 Dec 2022 18:28:07 -0500 Subject: [PATCH 2/3] Xavier - Complete random_cat_sei --- lib/index.html | 4 ++-- lib/script.js | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/index.html b/lib/index.html index 0e97ce8..6e13aea 100644 --- a/lib/index.html +++ b/lib/index.html @@ -14,8 +14,8 @@

Random Cat API

- -
+ +
diff --git a/lib/script.js b/lib/script.js index 8497fb1..0f29607 100644 --- a/lib/script.js +++ b/lib/script.js @@ -1,11 +1,11 @@ -const url = 'https://api.thecatapi.com/v1/images/search?api_key=e6f2adcdc125aef38c14ca0be4465d6a75b789e6.rtfd'; +const randoLink = 'https://api.thecatapi.com/v1/images/search?api_key=e6f2adcdc125aef38c14ca0be4465d6a75b789e6.rtfd'; const randButton = document.getElementById('randomButton'); randButton.addEventListener('click', randomCat); function randomCat () { -fetch(url) +fetch(randoLink) .then (res=>res.json()) .then( res => displayCat(res[0].url)) .catch(err => console.log('unsuccessful', err)); @@ -14,4 +14,8 @@ fetch(url) function displayCat(imgurl){ console.log(typeof(imgurl[0].url)); document.getElementById('randomCatImage').src=imgurl; -} \ No newline at end of file +} + +//function sortedRandomCat(){ + +//} \ No newline at end of file From 3f2eb94bb18c5918ff7191fccb9777445770cc2d Mon Sep 17 00:00:00 2001 From: ValtierraXavier Date: Wed, 7 Dec 2022 23:11:42 -0500 Subject: [PATCH 3/3] push id-codes into an array- -push category names into an array- -To do:use these to compare input and select appropriate id codes --- lib/index.html | 4 +-- lib/script.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/lib/index.html b/lib/index.html index 6e13aea..3e9542b 100644 --- a/lib/index.html +++ b/lib/index.html @@ -17,8 +17,8 @@

Random Cat API

- - + +
diff --git a/lib/script.js b/lib/script.js index 0f29607..bbbdf47 100644 --- a/lib/script.js +++ b/lib/script.js @@ -1,9 +1,21 @@ const randoLink = 'https://api.thecatapi.com/v1/images/search?api_key=e6f2adcdc125aef38c14ca0be4465d6a75b789e6.rtfd'; +const sortedLink = 'https://api.thecatapi.com/v1/images/search?breed_ids=beng'; +const sortID = 'https://api.thecatapi.com/v1/breeds'; const randButton = document.getElementById('randomButton'); +const sortedRandomButton = document.getElementById('searchButton'); +const inputFeild = document.getElementById('input'); +let category=[]; //to store whatever is input in the inputfeild +let idCode=[]; //to store the id's in an array +let catType=[]; //to store category names +let idVar; //what will be added to the URL for sort function to work randButton.addEventListener('click', randomCat); +//sortedRandomButton = document.addEventListener('click', sortedRandomCat) +// sortedRandomButton.addEventListener('click',sortedRandomCat); + +//fetches random-cat-api link for standard random output. function randomCat () { fetch(randoLink) .then (res=>res.json()) @@ -11,11 +23,68 @@ fetch(randoLink) .catch(err => console.log('unsuccessful', err)); } + +//Sets an to the recieved URL function displayCat(imgurl){ console.log(typeof(imgurl[0].url)); document.getElementById('randomCatImage').src=imgurl; } -//function sortedRandomCat(){ -//} \ No newline at end of file +//what will return the random categorized image +// function sortedRandomCat(){ +// fetch(sortedLink) +// .then(thing=>console.log("success", thing.json())) +// .catch("somethings wrong"); +// } + + +//fetches all picture attributes from api. used to creat an array of id codes. +function infoDump(){ + fetch(sortID) + .then((thang => thang.json())) + .then(thang =>makeIDarray(thang)) + .catch(console.log("unsuccessful")); +} + + +infoDump(); + + +//creats an array of id codes used to select the id code for the categories. +function makeIDarray(something){ + for(let i=0; i<67; i++){ + //console.log(something[i].id) + idCode.push(something[i].id); + + } + console.log(idCode); + return idCode; +} + + +//fetches all picture attributes from api. used to create an array of category names. +function getCategoryArray(){ + + fetch(sortID) + .then((thangs => thangs.json())) + .then(thangs =>makeCategoryArray(thangs)) + .catch(console.log("unsuccessful")); + +} + + +//creates an array of category names. will be used to compare category input to select appropriate id codes. +function makeCategoryArray(somethang){ + + for(let i=0; i<67; i++){ + //console.log(something[i].name) + catType.push(somethang[i].name); + + } + + console.log(catType); + return catType; + +} +getCategoryArray(); \ No newline at end of file