Skip to content

Commit

Permalink
Store highest score with localStrage at local side
Browse files Browse the repository at this point in the history
  • Loading branch information
lagagain authored and kidwm committed Jul 16, 2017
1 parent 61328f0 commit 1c8c162
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 + '<br>(' + 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 + '<br/>' + 'Your score: ' + total_score + '<br>(' + clicks + ' clicks in ' + score + ' seconds)');
ui.addClass('end').removeClass('play');
$('.twitter-share-button').remove();
$('.facebook-share-button').off('click');
Expand Down

0 comments on commit 1c8c162

Please sign in to comment.