'HTML .value checking not working properly

I have been working on a little coding project for my friends. This includes a somewhat password system that changes your username. I implemented this so that impersonation was harder to do.

<main class="join-main">
    <label for="password">Password</label>
    <input type="password" name="password" id="password" placeholder="Enter password..." required />
    <button type="button" onclick="fn1()">Check ig</button>
    <script>
        function fn1() {
            let pswvalue = document.getElementById("password").value

            if (pswvalue = "1234") {
                document.getElementById("username").value = "Hello"
            } else {
                return;
            }
        }
    </script>
    <form action="chat.html">
      <div class="form-control">
        <label for="username">Logging Into:</label>
        <input
          type="text"
          name="username"
          id="username"
          placeholder="The User you are logging into will appear here." 
          readonly
        />
      </div>
    </form>

For some reason, even if the password isn't "1234", The username still changes to Hello. Any suggestions on how to fix it?



Solution 1:[1]

It should be if (pswvalue === "1234") since we are comparing two stings.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Han Moe Htet