-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
137 lines (113 loc) · 4.21 KB
/
script.js
File metadata and controls
137 lines (113 loc) · 4.21 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
document.addEventListener("DOMContentLoaded", function() {
loadCSVFile();
});
function loadCSVFile() {
fetch('data.csv')
.then(response => response.text())
.then(contents => {
const rows = contents.split("\n").slice(1);
const users = [];
rows.forEach((row) => {
if (row.trim() === "") return;
const [email, username, profileUrl, skillBadges, arcadeGames, triviaBadges, points] = row.split(",");
users.push({
email: email.trim(),
username: username.trim(),
profileUrl: profileUrl.trim(),
skillBadges: parseInt(skillBadges.trim(), 10),
arcadeGames: parseInt(arcadeGames.trim(), 10),
triviaBadges: parseInt(triviaBadges.trim(), 10),
points: parseInt(points.trim(), 10),
});
});
window.users = users;
showLeaderboard();
})
.catch(error => {
console.error("Error loading CSV file:", error);
});
}
function getMilestone(skill, arcade, trivia, points) {
if (arcade >= 10 && trivia >= 8 && skill >= 44 && points >= 85) return "Milestone 5 🏆 ";
if (arcade >= 10 && trivia >= 8 && skill >= 44 && points >= 75) return "Milestone 4 🎯";
if (arcade >= 8 && trivia >= 7 && skill >= 30 && points >= 65) return "Milestone 3 🥉";
if (arcade >= 6 && trivia >= 6 && skill >= 20 && points >= 40) return "Milestone 2 🥈 ";
if (arcade >= 4 && trivia >= 4 && skill >= 10 && points >= 20) return "Milestone 1 🥇 ";
return "No Milestone Yet 🚧";
}
function displayUser() {
const emailInput = document.getElementById("email-input").value.trim();
const container = document.getElementById("result");
container.innerHTML = "";
if (!window.users) {
container.innerHTML = "<p>No user data available. Please reload the page or check the file.</p>";
return;
}
const user = window.users.find(u => u.email.toLowerCase() === emailInput.toLowerCase());
if (user) {
const { email, username, profileUrl, skillBadges, arcadeGames, triviaBadges, points } = user;
const milestone = getMilestone(skillBadges, arcadeGames, triviaBadges, points);
const card = document.createElement("div");
card.classList.add("user-card");
card.innerHTML = `
<h3>${username}</h3>
<p><strong>Email:</strong> ${email}</p>
<p><strong>Points:</strong> ${points}</p>
<p><strong>Milestone:</strong> ${milestone}</p>
<p><a href="${profileUrl}" target="_blank">Skill Profile 🔗</a></p>
`;
container.appendChild(card);
} else {
container.innerHTML = "<p>User not found. Please check the email address.</p>";
}
}
function showLeaderboard() {
const leaderboardContainer = document.getElementById("leaderboard");
leaderboardContainer.innerHTML = "";
if (!window.users || window.users.length === 0) {
leaderboardContainer.innerHTML = "<p>No user data available. Please reload the page or check the file.</p>";
return;
}
const sortedUsers = [...window.users].sort((a, b) => {
if (b.points !== a.points) {
return b.points - a.points;
}
return a.username.localeCompare(b.username); // Alphabetical order if points are equal
});
const table = document.createElement("table");
table.classList.add("leaderboard-table");
table.innerHTML = `
<thead>
<tr>
<th>Rank</th>
<th>Username</th>
<th>Email</th>
<th>Skill Badges</th>
<th>Arcade Games</th>
<th>Trivia Badges</th>
<th>Points</th>
<th>Milestone</th>
<th>Profile</th>
</tr>
</thead>
<tbody></tbody>
`;
const tbody = table.querySelector("tbody");
sortedUsers.forEach((user, index) => {
const milestone = getMilestone(user.skillBadges, user.arcadeGames, user.triviaBadges, user.points);
const row = document.createElement("tr");
row.innerHTML = `
<td>#${index + 1}</td>
<td>${user.username}</td>
<td>${user.email}</td>
<td>${user.skillBadges}</td>
<td>${user.arcadeGames}</td>
<td>${user.triviaBadges}</td>
<td>${user.points}</td>
<td>${milestone}</td>
<td><a href="${user.profileUrl}" target="_blank">View 🔗</a></td>
`;
tbody.appendChild(row);
});
leaderboardContainer.appendChild(table);
}