title: setting a localstorage high score and displaying it
body: <p>I have a tetris game that I am trying to finish but saving the high score after a game is over is causing me some issues. When the game ends, if the score is higher than what was previously saved as a highscore, it is supposed to save that new score as the high score locally and display that new highscore. I can not figure out why this is not happening. Below are the three different areas of my code that pertain to the high score. Any help would be appreciated. </p>
  
  <p>creates the menu on the side of the game</p>
  
  <pre><code> &lt;div id="tetris"&gt;
  &lt;div id="menu"&gt;
    &lt;p id="start"&gt;&lt;a href="javascript:play();"&gt;Press Space to Play.&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;&lt;canvas id="upcoming"&gt;&lt;/canvas&gt;&lt;/p&gt;
    &lt;p&gt;score &lt;span id="score"&gt;00000&lt;/span&gt;&lt;/p&gt;
    &lt;p&gt;rows &lt;span id="rows"&gt;0&lt;/span&gt;&lt;/p&gt;
    &lt;p&gt;high score &lt;span id="highscore"&gt;0&lt;/span&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;canvas id="canvas"&gt;
    Sorry, this example cannot be run because your browser does not support the &amp;lt;canvas&amp;gt; element
  &lt;/canvas&gt;
  </code></pre>
  
  <p></p>
  
  <p>sets the high score when the game is over</p>
  
  <pre><code>var highscore = localStorage.getItem("highscore");
  
    if (playing == false){
    if(highscore !==null){
        if(vscore &gt; highscore) {
            localStorage.setItem("highscore", vscore);
        }
    }
    else{
        localStorage.setItem("highscore", vscore);
    }
    }
    else{
        null;
    }
  </code></pre>
  
  <p>updates the scores to display them</p>
  
  <pre><code>function play() { hide('start'); reset();          playing = true;  }
  function lose() { show('start'); setVisualScore(); playing = false; }
  
  function setVisualScore(n)      { vscore = n || score; invalidateScore(); }
  function setScore(n)            { score = n; setVisualScore(n);  }
  function addScore(n)            { score = score + n;   }
  function clearScore()           { setScore(0); }
  function clearRows()            { setRows(0); }
  function setRows(n)             { rows = n; step = Math.max(speed.min, speed.start - (speed.decrement*rows)); invalidateRows(); }
  function addRows(n)             { setRows(rows + n); }
  function setHighScore(n)        { highscore = n; }
  function addHighScore(n)        { setHighScore(highscore); }
  function getBlock(x,y)          { return (blocks &amp;&amp; blocks[x] ? blocks[x][y] : null); }
  function setBlock(x,y,type)     { blocks[x] = blocks[x] || []; blocks[x][y] = type; invalidate(); }
  function clearBlocks()          { blocks = []; invalidate(); }
  function clearActions()         { actions = []; }
  function setCurrentPiece(piece) { current = piece || randomPiece(); invalidate();     }
  function setNextPiece(piece)    { next    = piece || randomPiece(); invalidateNext(); }
  
  function reset() {
    dt = 0;
    clearActions();
    clearBlocks();
    clearRows();
    clearScore();
    setCurrentPiece(next);
    setNextPiece();
  }
  
  function update(idt) {
    if (playing) {
      if (vscore &lt; score)
        setVisualScore(vscore + 1);
      handle(actions.shift());
      dt = dt + idt;
      if (dt &gt; step) {
        dt = dt - step;
        drop();
      }
    }
  }
  </code></pre>
  
  <p>I can add the full game code if needed but these are the three areas that directly pertain to the high score issue. </p>