JSFiddle - React, Tailwind, and code Playground

by Graham Fairweather

HTML

<button id="save10">Save 10</button>
<button id="save12">Save 12</button>

JavaScript

var highscore = 11,
    button10 = document.getElementById("save10"),
    button12 = document.getElementById("save12"),
    savedHighscore;

function saveData(x) {
    localStorage.setItem('highscore', x);
}

button10.addEventListener("click", function () {
    saveData(10);
}, false);

button12.addEventListener("click", function () {
    saveData(12);
}, false);

savedHighscore = parseInt(localStorage.getItem('highscore'), 10);
if (typeof savedHighscore === "number" && highscore <  savedHighscore) {
    highscore = savedHighscore;
}
    
alert("Highscore: " + highscore);