assets/js/script.js
// Storing the scores  in local storage
Storing the scores  in local storage
Storing the scores in local storage
function showTopScores() {
    playerName = document.getElementById('fname').value;
    console.log("the player name is ", playerName);
    if (playerName == "") {
        playerName = "Anonymous";
    };
    topScoreArray = JSON.parse(localStorage.getItem("topScoreArray")) || [];
    topScoreArray.push({playerName, score});
    topScoreArray.sort((a,b) => b.score - a.score);
    localStorage.setItem('topScoreArray', JSON.stringify(topScoreArray));
}
function showTopScores ( ) { playerName = document . getElementById ( 'fname' ) . value ; console . log ( "the player name is " , playerName ) ; if ( playerName == "" ) { playerName = "Anonymous" ; } ; topScoreArray = JSON . parse ( localStorage . getItem ( "topScoreArray" ) ) || [ ] ; topScoreArray . push ( { playerName , score } ) ; topScoreArray . sort ( ( a , b ) => b . score - a . score ) ; localStorage . setItem ( 'topScoreArray' , JSON . stringify ( topScoreArray ) ) ; }
Storing the scores  in local storage
Storing the scores in local storage