Maths Q&A game in JavaScript This used to be university work now I put it our here for review purposes.


Could this be constructed better?  
Is there any easier path, performance-wise?  
Could this be optimised?  
Which features and functionalities could/should be added to this game?  




&lt;!doctype html&gt; 
&lt;html&gt;

&lt;head&gt;
    &lt;title&gt;Math.floor&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

    &lt;h1&gt; Math.floor: The Maths Game&lt;/h1&gt;

    &lt;script&gt;
    // Universty work
    // @author Darik
    // Math.floor


        var score = 0;
        var times = 0;



        function questions(e) {
            var x = Math.floor(Math.random() * 11);
            var y = Math.floor(Math.random() * 11);
            var z = 0;
            var sign = '';

            if (e == 1) {
                sign = '+'
                z = x + y;
                interact(x, sign, y, z)
            } else if (e == 2) {
                sign = '-'
                z = x - y;
                interact(x, sign, y, z)
            } else if (e == 3) {
                sign = '/'
                z = x / y;
                interact(x, sign, y, z)
            } else {
                sign = '*'
                z = x * y;
                interact(x, sign, y, z)
            }

        }

        function interact(x, sign, y, z) {
            times++;
            var userAnswer = prompt("What is " + x + " " + sign + ' ' + y + "?");
            if (z == userAnswer) {
                document.write("&lt;p&gt;" + x + " " + sign + ' ' + y + " = " + userAnswer + " is correct &lt;/p&gt;");
                score = score + 1;
            } else {
                document.write("&lt;p&gt;" + x + " " + sign + ' ' + y + " = " + userAnswer + " &lt;span&gt; is INCORRECT. The correct answer is &lt;/span&gt; " + z + "&lt;/p&gt;");
            }
        }

        function _score() {
            if (times == score) {
                document.write('&lt;p&gt; A perfect score &lt;/p&gt;');
                document.body.style.backgroundColor = "#FF99CC";
            } else {
                document.body.style.backgroundColor = "#CCFFFF";
            }
            document.write('&lt;p&gt; You have answerd ' + score + ' questions out of ' + times + '&lt;/p&gt;');




        }


        questions(2);
        questions(1);
        questions(4);
        questions(3);
        _score()
    &lt;/script&gt;
&lt;/body&gt;

&lt;/html&gt;
You ask some unreasonable division questions.



That is answerable by the special string Infinity, but not infinity.



The expected answer is NaN, but responding with NaN will not work.




  10 / 3 = 3.33333333 is INCORRECT. The correct answer is 3.3333333333333335