-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.js
53 lines (45 loc) · 1.69 KB
/
results.js
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
// results.js
// Function to fetch election results from backend or local storage
function fetchResults() {
// Simulated results (replace this with actual backend or local storage logic)
const results = {
president: {
candidate1: 300,
candidate2: 450
},
secretary: {
candidate1: 400,
candidate2: 350
},
treasurer: {
candidate1: 500,
candidate2: 400
}
};
return results;
}
// Function to display election results on the page
function displayResults() {
const resultsContainer = document.getElementById('results-container');
const results = fetchResults(); // Fetch results
// Generate HTML for results table
let html = '<h2>President</h2><table><tr><th>Candidate</th><th>Votes</th></tr>';
for (const candidate in results.president) {
html += `<tr><td>${candidate}</td><td>${results.president[candidate]}</td></tr>`;
}
html += '</table>';
html += '<h2>Secretary</h2><table><tr><th>Candidate</th><th>Votes</th></tr>';
for (const candidate in results.secretary) {
html += `<tr><td>${candidate}</td><td>${results.secretary[candidate]}</td></tr>`;
}
html += '</table>';
html += '<h2>Treasurer</h2><table><tr><th>Candidate</th><th>Votes</th></tr>';
for (const candidate in results.treasurer) {
html += `<tr><td>${candidate}</td><td>${results.treasurer[candidate]}</td></tr>`;
}
html += '</table>';
// Display results on the page
resultsContainer.innerHTML = html;
}
// Call displayResults function when the page loads
window.onload = displayResults;