Skip to content

Commit

Permalink
Final Project
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuklaaa committed Jul 2, 2022
1 parent 84c9d27 commit f93c4a5
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
33 changes: 33 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
body {
background-color: skyblue;
}
h1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
border-radius: 20px;
font-family: Arial, Helvetica, sans-serif;
}
#myDiv {
width: 500px;
height: 400px;
background-color: coral;
margin: auto;
}
h2 {
text-align: center;
color: purple;
font-family: Arial, Helvetica, sans-serif;
padding-top: 20px;
}
pre {
font-family: Arial, Helvetica, sans-serif;
line-height: 50px;
margin-left: 50px;
font-size: 24px;
}
span {
color: white;
font-weight: bold;
}
20 changes: 20 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>COVID-19 CASES</title>
<link rel="stylesheet" href="./css/style.css">
</head>

<body>
<h1>Fetching Data using Covid API</h1>
<div id="myDiv">
<h2>Today Covid Cases</h2>
</div>
<script src="./js/script.js"></script>
</body>

</html>
40 changes: 40 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const url = "https://api.covid19api.com/summary";

getApiData = (url) => {
fetch(url)
.then((res) => {
return res.json();
})
.then((data) => {
console.log(data);

let country = data.Countries[77].Country;
let totalCases = data.Countries[77].TotalConfirmed;
let totalDeaths = data.Countries[77].TotalDeaths;
let newCase = data.Countries[77].NewConfirmed;
let newDeaths = data.Countries[77].NewDeaths;
let today = new Date().toDateString();

displayData(
country,
totalCases,
totalDeaths,
newCase,
newDeaths,
today
);
})
.catch((error) => {
console.log(error);
});
}

function displayData(c, tc, td, nc, nd, t) {
let pre = document.createElement("pre");
console.log(tc);
pre.innerHTML = `<span>Country Name: </span> ${c}\n<span>Date: </span> ${t} \n<span>Total Cases: </span> ${tc} \n<span>Total Deaths: </span>${td} \n<span>New Cases: </span>${nc} \n<span>New Deaths: </span>${nd}`;

document.getElementById("myDiv").appendChild(pre);
}

getApiData(url);

0 comments on commit f93c4a5

Please sign in to comment.