mardi 6 décembre 2016

JavaScript - Random integers multiplication

This is my first time using JavaScript, and so far I am completely lost. The idea behind the program is that I am aiming to have two numbers randomly generated as a multiplication question for the user to input the answer to. So for example the page would show two text boxes, one in which the question is asked and then another in which the user can answer the question

Basically, I am looking to use math.random to generate two integers (in a range from 1-6).

Then I am looking to create a function that displays these two random integers (For example, 3 times 6 is:..) while simultaneously using two variables (x,y) to hold the two numbers returned by the function.

There is much more to the program, however I am completely stumped with getting these steps alone working so far. If anyone has any ideas on how to fix the following code to complete these tasks that would be incredible:

    <script type="text/javascript">
    var x = 0, y = 0;
    function Number1(x, y) {
        return Math.floor (1+ Math.random() * 6 );
    }

    }

    function gatherQuestion() {
        din =  var x, y =document.getElementById("inputVal");
        dout = document.getElementById("outputVal");
        dout.value = Number1(din.value);
    }
</script>

I feel as though I am using the complete wrong features to attain a result but as mentioned prior, this is my first time using JavaScript and I am utterly at a loss. Many thanks for having a look!




Aucun commentaire:

Enregistrer un commentaire