Program works corectly two times after that it goes wrong
<p>After entering the correct answer twice, any subsequent try, even if the correct answer is entered again, shows the "try again" output. What is causing this strange behavior?</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;

    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
        &lt;title&gt;Untitled Document&lt;/title&gt;
        &lt;script type="text/javascript"&gt;
            var answer;
            var firstNum;
            var secondNum;
            var check = true;
            question();

            function question() {
                firstNum = Math.floor(Math.random() * 101);
                secondNum = Math.floor(Math.random() * 101);
                answer = firstNum * secondNum;
                document.writeln("&lt;h1&gt;How much is " + firstNum + " times " + secondNum + "&lt;/h1&gt;");
                document.writeln(answer);
                document.write('&lt;input name="inputAnswer" type="text" id="inputAns"/&gt;');
                document.write('&lt;input name="submitBtn" type="submit" value="Submit Answer" onclick="validate()"/&gt;');
            }

            function validate() {
                if (document.getElementById("inputAns").value == answer) {
                    document.write("Good");
                    check = true;
                    result();
                } else {
                    check = false;
                    document.write("try again");
                    result();
                }
            }

            function result() {
                if (check == true)
                    question();
                else {
                    document.writeln("&lt;h1&gt;How much is " + firstNum + " times " + secondNum + "&lt;/h1&gt;");
                    document.writeln(answer);
                    document.write('&lt;input name="inputAnswer" type="text" id="inputAns"/&gt;');
                    document.write('&lt;input name="submitBtn" type="submit" value="Submit Answer" onclick="validate()"/&gt;');
                }
            }
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body&gt;&lt;/body&gt;

&lt;/html&gt;
</code></pre>
