From 5a3697e98c227c65c20b606fadd1a12c38f6b403 Mon Sep 17 00:00:00 2001 From: Vasilis Myrianthopoulos Date: Thu, 22 Dec 2022 10:22:27 -0500 Subject: [PATCH] Finished --- lib/script.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/script.js b/lib/script.js index e69de29..29bc53b 100644 --- a/lib/script.js +++ b/lib/script.js @@ -0,0 +1,19 @@ +url = "https://api.thecatapi.com/v1/images/search"; + +const randomCat = document.querySelector(".randomButton"); +const randomCatImage = document.querySelector(".randomCatImage"); + +// const randomButton = image() +randomCat.addEventListener("click", image); + +function image() { + fetch(url) + .then((res) => { + return res.json(); + }) + .then((data) => { + randomCatImage.src = data[0].url; + console.log(data[0]); + }) + .catch((err) => console.log("wrong")); +}