assets/js/app.js
//Save the high score in local storage
Save the high score in local storage
Save the high score in local storage
function saveScore(e) {
    var getScores = JSON.parse(localStorage.getItem('scores'));
    if (getScores) {
        highScores = getScores;
    }
    if (activeQuiz == "JavaScript") {
        highScores.jsquiz.push(saveScoreArray());
    } else if (activeQuiz == "California") {
        highScores.caquiz.push(saveScoreArray());
    } 
    if (highScores.jsquiz.length > 1) {
        highScores.jsquiz.sort(function(a, b) {
            return parseInt(b.score) - parseInt(a.score);
        });
    }
    if (highScores.caquiz.length > 1) {
        highScores.caquiz.sort(function(a, b) {
            return parseInt(b.score) - parseInt(a.score);
        });
    }
    localStorage.setItem('scores',JSON.stringify(highScores));
    showHighScores();
}
function saveScore ( e ) { var getScores = JSON . parse ( localStorage . getItem ( 'scores' ) ) ; if ( getScores ) { highScores = getScores ; } if ( activeQuiz == "JavaScript" ) { highScores . jsquiz . push ( saveScoreArray ( ) ) ; } else if ( activeQuiz == "California" ) { highScores . caquiz . push ( saveScoreArray ( ) ) ; } if ( highScores . jsquiz . length > 1 ) { highScores . jsquiz . sort ( function ( a , b ) { return parseInt ( b . score ) - parseInt ( a . score ) ; } ) ; } if ( highScores . caquiz . length > 1 ) { highScores . caquiz . sort ( function ( a , b ) { return parseInt ( b . score ) - parseInt ( a . score ) ; } ) ; } localStorage . setItem ( 'scores' , JSON . stringify ( highScores ) ) ; showHighScores ( ) ; }
Save the high score in local storage
Save the high score in local storage
// Let's grab our stored scores // If there are scores stored, let's overwite our highScores array with them //Now based on which quiz, let's store our score // Sort the scores in order of highest to lowest if there are multiple entries