I have 1 script containing 3 functions. I have an issue were the confirmAnswer() function doesn't call the random() function.
<body>
<p>Get the random numbers...</p>
<button type="button" onclick="random()">Click Me!</button>
<p id="start"></p>
<p>Get the input...</p>
<p>Your answer is: <input type="text" id="textBox" value=""> </p>
<p id="textbox"></p>
<p>Get the answer...</p>
<button type="button" onclick="checkAnswer()">Click Me!</button>
<p id="checker"></p>
<p>Check the answer...</p>
<button type="button" onclick="confirmAnswer()">Check Answer!</button>
<p id="checkerChecker"></p>
<script>
var number1 = Math.floor((Math.random() * 12) + 1);
var number2 = Math.floor((Math.random() * 12) + 1);
var total = number1 * number2;
function random() {
document.getElementById("start").innerHTML = number1 + " x " + number2;
}
function checkAnswer() {
document.getElementById("checker").innerHTML = total;
}
function confirmAnswer() {
var answer = document.getElementById("textBox").value;
var theResult;
if (answer == total) {
theResult = "Yes, that is correct.";
random();
} else {
theResult ="No, that isn't correct.";
}
document.getElementById("checkerChecker").innerHTML = theResult;
}
</script>
</body>
I have used this function before, maybe it isn't the correct syntax to the original (below). Could anyone help me out?
<script>
function checkAnswer() {
var answer = document.getElementById("textBox").value;
var theResult;
if (answer == total) {
theResult = "Yes, that is correct.";
random();
} else {
theResult = "No, it's the wrong answer.";
clr();
}
document.getElementById("checker").innerHTML = theResult;
}
</script>
The only difference I can see between both is the 2nd piece of code invokes the random() function from another script.
snippetplease?