I am creating a game in javascript and I am accessing the high scores from a java spring server. All that is well, but when I get the top 10 scores and print them, I have a small formatting issue.
Looping through all values and printing the top 10 to the screen I get something like this:
- Derrick 20
- Derrick 20
- Derrick 20
- Derrick 20
- Derrick 20
- Derrick 20
- Derrick 20
- Derrick 20
- Derrick 20
- Derrick 20
(this forum auto fixes my issue, where 10 causes the name and score to be shifted 1 over from the other scores.)
That last line bothers me. In java, I could use string format. Can somebody help with how to do it in javascript?
This is my current way of printing it to the screen:
for(var a = 0; a < data.length; a++)
{
ctx.fillStyle = “red”;
ctx.font = “30px Arial”;
ctx.fillText((a+1) + " " + "User: " + data[a].name + " Score: " + data[a].score, 10, 30 + (a * 30));
}