title: Getting "Uncaught TypeError" on one function, while the other one which is the same works properly
body: <p>I have an issue with this function, returning an error: "Uncaught TypeError: storedId.indexOf is not a function. " and I have no idea how to get rid of it. The biggest issue is, that I have this very same function (this ones for movies, the other one is for tv shows), and the one for tv shows works as expected, while this one does not. To make it even worse, I had the same code on my github repo, where I was test-hosting the website, and it works perfectly there, and its literally the same code. Even tried copy-pasting the whole code for the whole script file, and it still returns the same error. The error started showing yesterday, when I went on to "tidy" my code as my project is 99% done, and just wanted to polish it out so I can then start hosting it. I have no idea why it does this, so any sort of help would help a lot, even guidance to what docs to read... Thanks in advance.</p>
  
  <p>Here's the function that gives me the error:</p>
  
  <pre><code>//Add movie to watch list. Bug - &gt; Uncaught TypeError: storedId.indexOf is not a function.
  function addToList(id){
      let storedId = JSON.parse(localStorage.getItem("movies")) || [];
      if(storedId.indexOf(id) === -1){
          storedId.push(id);
          localStorage.setItem("movies", JSON.stringify(storedId));
          //Notification that it will be added to Watchlist.
          const added = document.getElementById("added");
          added.innerHTML = "Added to watchlist !"
          added.classList.add("added");
          setTimeout(() =&gt; {
              added.classList.remove("added");
          }, 1500);
      } else {
          //Notification that it has already been added to the watchlist.
          const alreadyStored = document.getElementById("alreadyStored");
          alreadyStored.innerHTML = "Already in watchlist !"
          alreadyStored.classList.add("alreadyStored");
          setTimeout(() =&gt; {
              alreadyStored.classList.remove("alreadyStored");
          }, 1500);
      }
  }
  </code></pre>
  
  <p>If needed, here's the whole script file on hastebin:
  <a href="https://hastebin.com/licomupere.coffeescript" rel="nofollow noreferrer">https://hastebin.com/licomupere.coffeescript</a></p>