From 1c8c162e6dad875f9a349bee26b834fe38f64162 Mon Sep 17 00:00:00 2001 From: lagagain Date: Sun, 16 Jul 2017 01:18:39 +0800 Subject: [PATCH] Store highest score with localStrage at local side --- script.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index 269bba3..dd5718f 100644 --- a/script.js +++ b/script.js @@ -6,6 +6,7 @@ handleEvent:function(a){this.info.className=this.info.className.replace(/ ?appca var score; var cardsmatched; var clicks; +var highest_score; var ui = $("#game"); var uiIntro = $("#gameIntro"); @@ -263,8 +264,13 @@ function EndGame() { clearTimeout(scoreTimeout); playSound('applause'); // Define score formula - total_score = ( 33/(score/60) + 66/(clicks/24) ).toFixed(2); - $('#score').html('Your score: ' + total_score + '
(' + clicks + ' clicks in ' + score + ' seconds)'); + total_score = ( 33/(score/60) + 66/(clicks/24) ).toFixed(2); + highest_score = window.localStorage.getItem("highest_score") | 0; + if(total_score > highest_score){ + highest_score = total_score; + window.localStorage.setItem("highest_score", highest_score); + } + $('#score').html('Highest Score is '+ highest_score + '
' + 'Your score: ' + total_score + '
(' + clicks + ' clicks in ' + score + ' seconds)'); ui.addClass('end').removeClass('play'); $('.twitter-share-button').remove(); $('.facebook-share-button').off('click');