-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab6.html
65 lines (55 loc) · 2.21 KB
/
Lab6.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSC 225 Lab 5</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1 class="display-4"><i><u><b>PLEASE CLICK THE BUTTON TO RETIREVE INFORMATION FROM THE API</b></u></i>
</h1>
</div>
<br />
<br />
<div class="row justify-content-center">
<div class="col-sm-4">
<button type="button" id="btn1" onclick="GetData()"> CLICK ME!</button>
</div>
</div>
<br />
<br />
<div class="row justify-content-center">
<div class="col-sm-4">
<div class="label" id="lbl1">
<B>NO FACTS LOADED. PLEASE CLICK THE BUTTON.</B>
</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col-sm-4">
<img src="cat.png" id="img1" />
</div>
</div>
</body>
<script type="text/javascript">
async function GetData() {
const url = "https://brianobruno.github.io/cats.json";
const response = await fetch(url);
const data = await response.json();
data.facts.sort((a, b) => a.factId - b.factId);
let strbuilder = `<p><table style = "width:100%"><tr><th><b>Fact Number#</b></th><th><b>Fact</b></th></tr>`;
for (let i of data.facts) {
strbuilder += "<tr><td>" + i.factId + "</td><td>" + i.text + "</td></tr>";
}
strbuilder += "</table></p>";
document.getElementById("lbl1").innerHTML = strbuilder;
document.getElementById("img1").src=data.catPhoto
}
</script>