-
Notifications
You must be signed in to change notification settings - Fork 2
/
14.html
52 lines (48 loc) · 1.37 KB
/
14.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>task 14</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的列表中
*/
//先进行过滤,选出空气质量指数大于60的城市
var finalData = aqiData.filter(function(item, index, array){
return (item[1] > 60);
});
//对指数大于60的城市进行排序
finalData.sort(function(a, b){
return b[1] - a[1];
});
var aqiList = document.getElementById('aqi-list');
//将结果显示
var itemsHTML = '';
for(var i = 0; i < finalData.length; i++){
itemsHTML += '<li>第' + (i + 1) + '名:' + finalData[i][0] + '(样例) , ' + finalData[i][1] + '</li>';
}
aqiList.innerHTML = itemsHTML;
})();
</script>
</body>
</html>