title: JavaScript - "Identifier has already been declared"
body: <p>Having an issue with getting a register/ login form to work on HTML using localStorage. As part of my assignment, I cannot use databases or php even though these are easier. Specifically the issue is occurring during my submit function.</p>
  
  <p>The syntax error coming back is "Identifier registerUser has already been declared", and highlights <code>const reponse = processUser (username.value, password.value)</code> in the console. </p>
  
  <p>Here's my JavaScript code:</p>
  
  <pre><code>//setup form
  window.addEventListener("DOMContentLoaded", setupForm);
  
  function setupForm() {
      const form = document.getElementById("login");
      form.addEventListener("submit", handleSubmit);
  }
  
  //handle Submit
  function handleSubmit(event) {
      event.preventDefault();
  
      const {
          Username,
          Password,
          login_type,
          result
      } = event.target;
  
      const processUser = login_type.value == "register" ? registerUser : loginUser;
      const response = processUser(username.value, password.value);
      result.innerHTML = response;
  }
  
  //register new user
  function registerUser(username, password) {
      window.localStorage.setItem("username", username);
      window.localStorage.setItem("password", password);
  
      return 'New user ${username} now registered!';
  }
  
  //login existing user
  function loginUser(username, password) {
      const registeredUser = window.localStorage.getItem("username", username);
      const registeredUser = window.localStorage.getItem("password", password);
  
      const validUser = username == registeredUser;
      const validPassword = password == registeredUser;
  
      if (validUser &amp;&amp; validPassword) {
          return 'User ${username} successfully logged-in!';
      }
      //error form for incorrect username or password
      else if (!validUser) return 'Incorrect username or password';
  }
  </code></pre>
  
  <p>HTML form:</p>
  
  <pre><code>&lt;fieldset&gt;
      &lt;form id="login" action="submit" method="post"&gt;
          &lt;legend&gt;&lt;b&gt;Login here!&lt;/b&gt;&lt;/legend&gt;&lt;br /&gt;
          &lt;div&gt;
              &lt;label for="username"&gt;Username:&lt;/label&gt;
              &lt;input id="username" type="text" name="username" required /&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;label for="password"&gt;Password:&lt;/label&gt;
              &lt;input id="password" type="password" name="Password" required /&gt;
          &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;span&gt;
      &lt;input id="login" type="hidden" name="login_type" value="login" checked="checked"&gt;&lt;/input&gt;
      &lt;!--Hidden for the purposes of my script working--&gt;
      &lt;input type="submit" value="Submit" /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;output name="result"&gt;&lt;/output&gt;
      &lt;/fieldset&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated as this is very frustrating!</p>