I'm totally new to JavaScript and could really use some help... I have to make a program in JavaScript that randomly generates two numbers between 1 and 12 and stores them into a text field. These two numbers are global variables and are sent to a function that displays the text field string as "x times y" (x and y being the randomly generated numbers). It should also have a check answer button that uses window.alert to compare the answer entered to the correct answer and will be a message shown depending on the answer they give. I haven't done much on it so I apologise for the lack of code but any help would be really helpful as it's for a class assignment. Thank you!
<script type="text/javascript">
var x, y;
function aNumber(x, y) {
Math.floor((Math.random() * 12) + 1);
Math.floor((Math.random() * 12) + 1);
return x, y;
}
function genQuestion(x, y) {
document.getElementById('question').value = aNumber(x) + "times" + aNumber(y);
}
</script>
</head>
<body>
<h1>Learning Multiplication</h1>
<form name="myForm" id="myForm" action="#">
<label>What is: </label>
<input id="question" name="question" type="text" />
<br>
<label>The answer is: </label>
<input id="answer" name="answer" type="text" />
<br>
<label>Correct answers: </label>
<input id="total" name="total" type="text" />
<br>
<button class = "button" name="button" type="button" value="Check answer" onclick="genQuestion()" />
</form>
</body>
Aucun commentaire:
Enregistrer un commentaire