Last active
September 11, 2021 22:30
-
-
Save kirkegaard/4139a544e8b183cd86e2c4bd6a232d28 to your computer and use it in GitHub Desktop.
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"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<script> | |
const endpoint = "https://api.covid19api.com/world/total"; | |
const fetchData = async () => { | |
try { | |
const res = await fetch(endpoint); | |
if (!res.ok) { | |
const { message } = await res.json(); | |
throw Error(message); | |
} | |
return await res.json(); | |
} catch (err) { | |
alert(err); | |
} | |
} | |
const mapData = async () => { | |
const data = await fetchData(); | |
for (const [key, value] of Object.entries(data)) { | |
document.querySelector(`#${key} .content`).innerHTML = value.toLocaleString(); | |
} | |
} | |
mapData(); | |
</script> | |
<style> | |
body, html { | |
font-family: arial; | |
font-size: 14px; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
background-color: #222; | |
color: #fff; | |
} | |
.boxes { | |
height: 100%; | |
display: flex; | |
flex-direction: row; | |
justify-content: center; | |
align-items: center; | |
} | |
.box { | |
display: flex; | |
align-items: center; | |
flex-direction: column; | |
padding: 20px; | |
margin: 10px; | |
box-shadow: 0px 7px 4px rgba(0,0,0,0.1); | |
background-color: #282828; | |
border-radius: 10px; | |
min-width: 200px; | |
} | |
.title { | |
font-size: 1.2em; | |
margin-bottom: 0; | |
} | |
.content { | |
font-size: 3em; | |
font-weight: bold; | |
margin: 1rem; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="boxes"> | |
<div class="box" id="TotalConfirmed"> | |
<h3 class="title">Confirmed</h3> | |
<p class="content"></p> | |
</div> | |
<div class="box" id="TotalDeaths"> | |
<h3 class="title">Deaths</h3> | |
<p class="content"></p> | |
</div> | |
<div class="box" id="TotalRecovered"> | |
<h3 class="title">Recovered</h3> | |
<p class="content"></p> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment