title: I'm making a simple arithmetic game that keeps generating two operand and a operator as long as the user inputs right answer to the arithmetic
body: <p>This is my code that is randomly generating the operand and operator:</p>
  
  <pre><code>function gameLogic() {
    var mySymbol = ['+', '-', '*', '/', '%']
    number1 = Math.floor((Math.random() * 10) + 1);
    number2 = Math.floor((Math.random() * 10) + 1);
    operator =
    mySymbol[Math.floor(Math.random() * mySymbol.length)];
  
    exp = number1 + operator + number2
    answer = Math.floor(eval(exp))
    //alert(answer)
  
    document.getElementById("number1").innerHTML = number1;
    document.getElementById("operator").innerHTML = operator;
    document.getElementById("number2").innerHTML = number2;
  
    document.getElementById("maininput").focus();
    document.getElementById("maininput").select();
  }
  </code></pre>
  
  <p>This is function that gets invoked when user press start game button(the start game button is the initial page):</p>
  
  <pre><code>function startGame() {
    document.getElementById("first").style.display = 'none';
    document.getElementById("second").style.display = 'block';
  
    gameLogic()
  }
  </code></pre>
  
  <p>This function controls the onkeypress actions:</p>
  
  <pre><code>document.onkeypress = function returnAnswer() {
    if (event.keyCode == 13 || event.which == 13) {
      var x = document.forms["main"]["answerForm"].value;
      //alert(answer);
      if (x == answer) {
        //continue Game
        startGame();
      } else {
        alert("Game Over");
      }
    }
  
  }
  </code></pre>
  
  <p>answer is global variable set to 0 initially.
  The code is displaying two operand and one operator initially, then when i press enter to submit, if the answer is correct, instead of just changing the operand and operator, it displays the main page with start game button again. Please help !!</p>