From e53135d1164a9989cfc1305e298112842e8774d9 Mon Sep 17 00:00:00 2001 From: orpichardo Date: Wed, 14 Dec 2022 11:09:12 -0500 Subject: [PATCH] Orlando HW Random Cats --- lib/index.html | 1 + lib/script.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/index.html b/lib/index.html index 0e97ce8..5ed24e2 100644 --- a/lib/index.html +++ b/lib/index.html @@ -1,3 +1,4 @@ + diff --git a/lib/script.js b/lib/script.js index e69de29..1c77767 100644 --- a/lib/script.js +++ b/lib/script.js @@ -0,0 +1,28 @@ +const url= "https://api.thecatapi.com/v1/images/search" +let header = { + "x-api-key": + "live_c7NFwQNovYorkhRwoYbtV1ytRgM1c7I3KmWGi5ucgGsnk1aBvtmJfe4HDV36SJzd" +} +const catButton = document.querySelector(`.randomButton`); +catButton.addEventListener('click', handleClick) + + +function handleClick() { +fetch(url, {header}) + .then((res) => res.json()) + .then((res) => { + let randImage = document.querySelector(".randomCatImage"); + randImage.src = res[0].url; + }); +} + + + + + + + + + + +