Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Cards API
Browse files Browse the repository at this point in the history
  • Loading branch information
eoussama committed Jan 11, 2024
1 parent 533eab0 commit 5064d3d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
window.addEventListener('DOMContentLoaded', () => {
fetch('https://disease.sh/v3/covid-19/historical/all?lastdays=all')
fetch('https://disease.sh/v3/covid-19/all')
.then(e => e.json())
.then(e => ({
cases: e.cases,
deaths: e.deaths,
recovered: e.recovered
}))
.then(data => {
const keys = Object.keys(data);

for (const key of keys) {
const number = getLastRecordedStat(data, key);
const number = data[key];
const counter = new countUp.CountUp(`stat-${key}`, number);

counter.start();
}
});

function getLastRecordedStat(data, key) {
const stat = Object
.entries(data[key])
.reverse()
.find(e => e[1] > 0);

return stat[1] || 0;
}
});

0 comments on commit 5064d3d

Please sign in to comment.