-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (57 loc) · 2.37 KB
/
Copy pathscript.js
File metadata and controls
70 lines (57 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$(document).ready(function () {
var googleAPIkey = "18c881248ae94a0eb9c6e2320f2ab227";
getWorldConfirmedCases();
getAusConfirmedCases();
getWorldNews();
function getWorldNews() {
$.ajax({
url: "https://newsapi.org/v2/everything?q=corona%20or%20covid&language=en&sortedBy=popularity&apiKey=" + googleAPIkey,
method: "GET"
})
.then(populateNews)
.fail(errormsg);
}
function populateNews(response) {
for (let i = 0; i < 3; i++) {
let title = $("<h3>").text(response.articles[i].title).attr("id", "title");
let desc = $("<p>").text(response.articles[i].description).attr("id", "description");
let articleLink = $("<a target='_blank'>").text("click here to read the full article").attr({
"class": "linkstyle",
"href": response.articles[i].url,
"target": "_blank"
});
$(`#worldNews${i}`).prepend(title, desc);
$(`.worldNews${i}`).prepend(articleLink);
}
}
//error message that is going to be shown.
function errormsg() {
console.log("Unable to get any data");
}
// Function to get total confirmed and recovered cases in Australia
function getAusConfirmedCases() {
$.ajax({
url: "https://corona-api.com/countries/AU",
method: "GET"
}).done(getAuTotal).fail(errormsg)
}
function getAuTotal(response) {
let confirmedCases = response.data.latest_data.confirmed;
let recoveredCases = response.data.latest_data.recovered;
$("#numberAusCases").text("Australian confirmed cases: " + confirmedCases);
$("#numberAusRecovCases").text("Australian recovered cases: " + recoveredCases);
}
// Function to get total confirmed and recovered cases world wide
function getWorldConfirmedCases() {
$.ajax({
url: "https://corona-api.com/timeline",
method: "GET"
}).done(getWorldTotal).fail(errormsg)
}
function getWorldTotal(response) {
let confirmedCases = response.data[0].confirmed;
let recoveredCases = response.data[0].recovered;
$("#numberWorldCases").text("World confirmed cases: " + confirmedCases);
$("#numberWorldRecovCases").text("World recovered cases: " + recoveredCases);
}
});