Adding a high score to local storage

后端 未结 5 1877
轻奢々
轻奢々 2021-01-06 16:37

I want to add a high score to my game. Right now I have this:

var score = 0;
var highscore = 0;

The score variable works but whenever I get

5条回答
  •  悲哀的现实
    2021-01-06 17:21

    if (score > parseInt(localStorage.getItem('highscore'), 10)) {
      localStorage.setItem('highscore', score);
    }
    

    convert into int before comparing. its string

提交回复
热议问题