trouble with comparing strings in javascript
<p>I'm having a weird issue in JS comparing strings. One string is from a user input.</p>

<pre><code>y = data;
document.getElementById("typeThisWord").innerHTML = y;
x = document.getElementById("inputField");
document.getElementById("youTyped").innerHTML = x.value;
first = document.getElementById("youTyped");
second = document.getElementById("typeThisWord");
if(first==second) correct=true;
</code></pre>

<p>When the words are the same, it still comes out false. I added in the 'first' and 'second' variables just to see if it would make a difference. Previously I've tried just comparing 'x' to 'y'. I've also tried x.value==y, x==y.value, and x.value==y.value. THe same with 'first' and 'second.' Surprisingly first.value==second.value came out to be true all the time, even when it shouldn't be.</p>

<pre><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script&gt;
        var x, y;
        var first, second;
        var availV = window.innerHeight - 100;
        var availH = window.innerWidth - 100;
        var randV, randH;
        var correct = new Boolean(); correct=true;
        var imageX;
        function displayWord() {

            if(correct) {
                correct=false;
                $.ajax({
                    url: "http://localhost:25578/TypeGood/VisitsSession",
                    success: function(data) { y = data; },
                    async: false
                });
                document.getElementById("typeThisWord").innerHTML = y;
                imageX = document.createElement("img");
                imageX.src = "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRPRV4XdE7C9sa0pM-FeXcOSQydg7Sh0INg-ZD6FKZ4wjY8WPHa5Q";
                imageX.height = 100;
                imageX.width = 100;
                imageX.style.position = "absolute";
                randV = Math.round( Math.random() * availV );
                randH = Math.round( Math.random() * availH );
                imageX.style.top = randV + "px";
                imageX.style.left = randH + "px";
                imageX.style.zIndex = "-20";
                document.body.appendChild(imageX);
            }
            x = document.getElementById("inputField");
            document.getElementById("youTyped").innerHTML = x.value;
            first = document.getElementById("youTyped").innerHTML;
            second = document.getElementById("typeThisWord").innerHTML;
            if(first==second) {correct=true;}
            x.value = "";

        }
    &lt;/script&gt;
</code></pre>
