Created
November 24, 2019 09:36
-
-
Save Toinne/c1b9475bd793baf30f6e87590dc22e8a to your computer and use it in GitHub Desktop.
Fetch exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<h2><a href="https://aws.random.cat/" target="_blank">a random cat website</a></h2> | |
<p>this page also has an API to get random cat images, so use it already!</p> | |
<button id="get-random-cat">load a random cat</button> | |
<div id="cat-space"></div> | |
<script> | |
function getRandomCatHandler() { | |
// make api request | |
fetch("https://aws.random.cat/meow", { method: "GET" }) | |
.then(response => response.json()) | |
.then(catData => { | |
// render data to DOM | |
/* | |
do a little dom manipulation to clear the cat-space | |
and to put in the new image from catData | |
*/ | |
}) | |
.catch(err => console.log(err)) | |
} | |
document.getElementById("get-random-cat") | |
.addEventListener("click", getRandomCatHandler); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment