aboutsummaryrefslogtreecommitdiff
path: root/src/highscores.js
blob: 82db612ce21bf279e41c5fa10b8dee9c6463154a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function submitScore(game, score, username){
    // Prompt for the username
    if(username == undefined){
        username = prompt("Enter a name to submit score", "");
    }
    // If the user filled out the prompt, post the score
    if (!(username  == null || username == "")) {
        // Get a uuid to identify this request by (for idempotency)
        fetch(new Request(`/uuid`))
        .then(response => response.text()
        .then(uuid => {
            const request = new Request(`/setScore?game=${game}&username=${username}&score=${score}&uuid=${uuid}`);
            fetch(request);
        }));
        
    } 
    // Return the username for later use by the game
    return username
}