Creating a leaderboard in HTML/JS

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Creating a leaderboard in HTML/JS



I'm trying to create a top 10 leaderboard, for now, I've only implemented 3 players, but I'm coming across an issue. My script doesn't seem to be outputting anything on webpage.



The purpose of the script is to compare 3 arrays, player1,player2,and player3 solely based off of score. Which is the 2nd index of each array. I want the script to list the players in order of highest score.



This method doesn't really seem to be efficient, especially when I'll have to add 7 more players. Could someone suggest perhaps an easier approach, as well as show me why my script wont output the info.



Here's the JS


function leaderboard() {
var player1 = name:"Thomas",date:"01/23/18",score:"201";
var player2 = name:"Michael",date:"03/24/17",score:"943";
var player3 = Name:"Lisa",date:"06/04/18",Score:"79";

if(player1[2]>player2[2])&&(player1[2]>player3[2])
document.write(player1);
if(player2[2]>player3[2])
document.write(player2);
document.write(player3);

else
document.write(player3);
document.write(player2);


else if(player2[2]>player1[2])&&(player2[2]>player3[2])
document.write(player2);
if(player1[2]>player3[2])
document.write(player1);
document.write(player3);

else
document.write(player3);
document.write(player1);



else if(player3[2]>player2[2])&&(player3[2]>player1[2])
document.write(player3);
if(player1[2]>player2[2])
document.write(player1);
document.write(player2);

else
document.write(player2);
document.write(player1);






Here's my html


<html>
<body>
<div id="container">
<script src = "topten.js"</script>
<script>
leaderboard();
</script>
<link rel="stylesheet" type="text/css" href="/css/topten.css">
</html>
</body>









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard