Skip to content

Latest commit

 

History

History
69 lines (61 loc) · 2.08 KB

leaderboard.md

File metadata and controls

69 lines (61 loc) · 2.08 KB

Leaderboard

<style> #recentGames{ width: 100%; color:white; border: 2px solid #009614; } </style>
Username Distance Score Date Location
<script> // Function to update the leaderboard function updateLeaderboard() { console.log('Updating leaderboard...'); // Make the asynchronous GET request to retrieve leaderboard data from the API $.getJSON('https://school.aipad-techs.com/api/leaderboardUser/getMaxScore') .done(function (data) { // Clear the current leaderboard on update $('#recentGames').empty(); // Add labels to the leaderboard table var labelsRow = '' + 'Name' + 'Score' + 'Date' + 'Locations' + 'Total Distance' + ''; $('#recentGames').append(labelsRow); // Adds the new data to the leaderboard from the API response data.forEach(function (entry) { var name = entry.name; var score = entry.score; var date = entry.dateG; var locations = Array.isArray(entry.locations) ? entry.locations.join(', ') : ''; var totalDistance = entry.tot_distance; var row = '' + '' + name + '' + '' + score + '' + '' + date + '' + '' + locations + '' + '' + totalDistance + '' + ''; $('#recentGames').append(row); }); console.log('Leaderboard updated.'); }) .fail(function (error) { console.log('Error:', error); }); } setInterval(updateLeaderboard, 1000); </script>