-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpiderTask1page3.html
More file actions
55 lines (47 loc) · 1.67 KB
/
SpiderTask1page3.html
File metadata and controls
55 lines (47 loc) · 1.67 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
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="SpiderTask1page3.css">
<title>Spider Induction Task1 page2</title>
</head>
<body onload="printLeaderboard()">
<div id="heading"><h1>Leader Board</h1></div>
<div class="mainflex">
<table id="leaderboard">
</table>
<button id="gohome">Homepage</button>
</div>
<script>
document.getElementById("gohome").addEventListener("click",function(){
location.href="SpiderTask1page1.html";
})
function printLeaderboard() {
var d =[];
let p;
let i;
let temp;
for (i=0; i<localStorage.length ; i++){
p=localStorage.key(i);
if((p.includes("scores")) && p!="scorestatus"){
d.push(p.slice(0,-6));
}
}
for(i=0; i<d.length-1; i++){
for(j=0; j<d.length-i-1; j++){
if(Number(localStorage.getItem(d[j]+"scores"))<Number(localStorage.getItem(d[j+1]+"scores"))){
temp = d[j];
d[j] = d[j+1];
d[j+1] = temp;
}
}
}
let text = "<tr><th>Rank</th><th>Name</th><th>High score</th></tr>";
for(let i = 0; i<d.length; i++){
text += "<tr><td>"+(i+1)+"</td><td>"+d[i]+"</td><td>"+localStorage.getItem(d[i]+"scores")+"</td></tr>";
}
document.getElementById("leaderboard").innerHTML = text;
}
</script>
</html>