-
Notifications
You must be signed in to change notification settings - Fork 0
/
ife_task_2.2.html
65 lines (55 loc) · 1.25 KB
/
ife_task_2.2.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>
<head>
<meta charset="utf-8">
<title>IFE JavaScript Task 01</title>
</head>
<body>
<h3>污染城市列表</h3>
<ul id="aqi-list">
<!--
<li>第一名:福州(样例),10</li>
<li>第二名:福州(样例),10</li> -->
</ul>
<script type="text/javascript">
var aqiData = [
["北京", 90],
["上海", 50],
["福州", 10],
["广州", 50],
["成都", 90],
["西安", 100]
];
(function () {
/*
在注释下方编写代码
遍历读取aqiData中各个城市的数据
将空气质量指数大于60的城市显示到aqi-list的列表中
*/
function bigtosmall (a, b) {
return -(a[1]-b[1]);
}
aqiData.sort(bigtosmall);
var ul = document.getElementById('aqi-list');
var i;
var selected = [];
for (i = 0; i < aqiData.length; i ++) {
var aqiNumber = aqiData[i];
if (aqiNumber[1] > 60){
selected[i] = aqiData[i];
}
else break;
}
var li1 = document.createElement('li');
var li2 = document.createElement('li');
var li3 = document.createElement('li');
li1.innerHTML = '第一名:' + selected[0];
ul.appendChild(li1);
li2.innerHTML = '第二名:' + selected[1];
ul.appendChild(li2);
li3.innerHTML = '第三名:' + selected[2];
ul.appendChild(li3);
})();
</script>
</body>
</html>