I Cannot figure out this single script problem

iv been trying to look for a way to save my div on a local storage so it doesn’t show up again but I’m having trouble getting it to work

      <div>
        <!-- Button to hide  
      * may add js to locally save and not showup again--> <button type="button" class="btn btn-primary btn-sm"
          onclick="hidediv()">Understood</button>
        <script>
          function hidediv() {
            var x = document.getElementById("hidemeonclick");
            if (x.style.display === "none") {
              x.style.display = "block";
            } else {
              x.style.display = "none";
            }
            if (localStorage.getItem(hidediv) === 1) {
              // Local Storage to grab and locally hide div for {IPUSER}
              console.log("Function Failed")
            } else {
              console.log("div hidden")
              x.style.display === "none";
            }
          }
        </script>
      </div>

Answer

Quite a few errors in your code. As others have mentioned, localStorage only stores strings so you shouldn’t compare strict with a number. You’re also using a === operator to set the style.display to none. Not really sure what you’re trying to do here but this code will persistently hide a div based on the button being clicked

<div id="hidemeonclick">I'll be hidden</div>
<button id='btn' onclick="hidediv()">Click me to hide div</button>

if (localStorage.getItem('hidediv') === 'hide') {
  var x = document.getElementById("hidemeonclick");
  x.style.display = "none";
}

function hidediv() {
  var x = document.getElementById("hidemeonclick");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
  localStorage.setItem('hidediv', 'hide');
}