title: Javascript local storage API theme switch not working
body: <p>I'm trying to do a course home work and I've write this from a youtube video but it's not working!! it's about add 2 buttons in html page to switch between to css classes and also use local storage API to save the last choice in local and when load the page it will remember the last choice.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function applyTheme (theme) {
      "use strict"
   document.getElementById("mypage").className = theme;
   localStorage.setItem ("theme", theme); 
  }
  
  function applyDayTheme () {
          "use strict"
  
   applyTheme("day");
  }
  
  function applyNightTheme() {
          "use strict"
  
   applyTheme("night");
  
  }
  
  function addButtonLestenrs () {
          "use strict"
  
   document.getElementById("b1")addEventListener("click", applyDayTheme);
   document.getElementById("b2")addEventListener("click", applyNightTheme);
  
  }
  
  function initiate(){
          "use strict"
  
   if(typeof(localStorage)===undefined)
    alert("the application can not be executed properly in this browser");
   else{
    if(localStorage.getItem("theme")===null)
     applyDayTheme();
    else
     applyTheme(localStorage.getItem("theme"));
    
   }
   addButtonLestenrs();
  }
  
  initiate();</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.day{
  color:black;
  background-color:lightgrey;
  }
  .night{
  color:white;
  background-color:black;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
   &lt;meta charset="utf-8"&gt;
   &lt;link rel="stylesheet" href="css/style.css"&gt;
   
  &lt;/head&gt;
  &lt;body id="mypage"&gt;
   &lt;h1&gt;Choose a theme&lt;/h1&gt;
   &lt;button id="b1"&gt;Theme day&lt;/button&gt;
   &lt;button id="b2"&gt;Theme night&lt;/button&gt;
   
   &lt;p&gt; This is an example of use of HTML5 storage API &lt;/p&gt;
  
  
  &lt;script type="text/javascript" src="js/script.js"&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>