From 64b8d27ed12cf071e1484b26bc28e92881c906c3 Mon Sep 17 00:00:00 2001 From: layz1008 Date: Thu, 5 Jan 2023 08:58:38 -0500 Subject: [PATCH] Zack Lay --- lib/script.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/script.js b/lib/script.js index e69de29..35265d3 100644 --- a/lib/script.js +++ b/lib/script.js @@ -0,0 +1,31 @@ +const url = "https://api.thecatapi.com/v1/images/search"; +const btnRand = document.querySelector('.randomButton'); +const reset = document.querySelector('.randomButton'); +const divCat = document.querySelector('.categoryCat') + +const yarnBall = (e) => { + e.preventDefault(); + + fetch(url) + .then(res => { + return res.json(); + }) + .then((data) => { + displayCat(data) + console.log(data) + }) + + .catch(err => console.log('oops', err)); +} + +function displayCat(catPic) { + const catPicHTML = ` + Cat Pic + `; + while (divCat.childNodes.length > 0) { + divCat.removeChild(divCat.firstChild) + } + divCat.insertAdjacentHTML("beforeend", catPicHTML); +} + +btnRand.addEventListener('click', yarnBall) \ No newline at end of file