输入正确的输入时,if 语句不适用于 DOM

When inputting the correct input, if statement doesn't work with DOM

我想知道为什么这不起作用:当我输入“1234”并按下按钮时,没有任何反应。谁能帮我解决这个问题?

<head>
    <title>Your Website!</title>
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
    <h1 class="w3-container w3-green w3-center"> | YOUR WEBSITE | </h1>
    <h3 class="w3-aqua w3-spin w3-left">AMAZING</h3>
    <h2 class="w3-green w3-center">Type in "1234"</h2>
    <input id="inputArea"></input>
    <button class="w3-btn w3-red" onclick="pressed()">Try it</button>
    <script>
        function pressed() {
            var i = document.getElementById(inputArea).value;
            if (i = "1234") {
                alert("PASSWORD CORRECT");
            }else {
                alert("PASSWORD INCORRECT");
            }

        }
    </script>
</body>

您忘记将输入 ID 放在“. 这是工作代码:

  <head>
    <title>Your Website!</title>
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
    <h1 class="w3-container w3-green w3-center"> | YOUR WEBSITE | </h1>
    <h3 class="w3-aqua w3-spin w3-left">AMAZING</h3>
    <h2 class="w3-green w3-center">Type in "1234"</h2>
    <input id="inputArea"></input>
    <button class="w3-btn w3-red" onclick="pressed()">Try it</button>
    <script>
        function pressed() {
            var i = document.getElementById("inputArea").value;
            if (i = "1234") {
                alert("PASSWORD CORRECT");
            }else {
                alert("PASSWORD INCORRECT");
            }

        }
    </script>
</body>