I am creating a simple video game leader board which will rank the user score against pre-set scores which will place their rank from highest to lowest depending.
<html>
<!Foundation Page for building our Javascript programs>
<head>
<title>The Foundation Page </title>
<script type="text/javascript">
function leaderboard()
{
var leaderboardarray = new Array (5);
var n, temp;
ok=false;
var score
var rank
score = 150
leaderboardarray[1] = 50;
leaderboardarray[2] = 60;
leaderboardarray[3] = 180;
leaderboardarray[4] = 120;
leaderboardarray[5] = score;
while(!ok)
{
ok = true
for (n=1; n<=5; n=n+1)
{
if (leaderboardarray [n]<leaderboardarray [n-1])
{
leaderboardarray [n] = leaderboardarray [n-1];
ok = false;
}
}
}
for (n=5; n>=1; n=n-1)
document.write (leaderboardarray [n] + "<br>");
}
</script>
</head>head>
<body BGCOLOR="WHITE">
<h2>The Foundation Page </h2>
<hr>
<script LANGUAGE="Javascript"> leaderboard() </script>
</body>
</html>
Its outputting the arrays as normal, but I am stuck on how the array outputs a value from highest to lowest. When I place a value higher than any other value after it, it will only produce the same value. When I change one of the value to Would anyone suggest on what I should do to do so would be much appreciated. I am still new to programming so sorry if I am doing anything silly. Thank you!