-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.html
68 lines (60 loc) · 2.1 KB
/
sample.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
66
67
68
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Franklin (Sample)</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
</head>
<body>
<header>
<h1>
Franklin (Sample)
</h1>
</header>
<main>
<section>
<article>
<p>
Motto: <span id="motto"></span>
</p>
<p>
Year Founded: <span id="yearFounded"></span>
</p>
<p>
Population: <span id="currentPopulation"></span>
</p>
<p>
Average Rainfall: <span id="averageRainfall"></span>
</p>
<p>Events:</p>
<ul id="events">
</ul>
</article>
</section>
</main>
<script>
var townData;
var requestURL = 'https://byui-cit230.github.io/towndata.json';
var request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'json';
request.send();
request.onload = function() {
townData = request.response;
for (var i = 0; i < townData.towns.length; i++) {
if (townData.towns[i].name === "Franklin") {
document.getElementById("motto").innerHTML = townData.towns[i].motto;
document.getElementById("yearFounded").innerHTML = townData.towns[i].yearFounded;
document.getElementById("currentPopulation").innerHTML = townData.towns[i].currentPopulation;
for (var j = 0; j < townData.towns[i].events.length; j++) {
var newListItem = document.createElement("li");
newListItem.innerHTML = townData.towns[i].events[j];
document.getElementById("events").append(newListItem);
}
}
}
}
</script>
</body>
</html>