I'm trying to create a script that represents an elementary grade multiplication aid. The script chooses two random numbers and multiplies them together. You then enter your answer and if it is correct it states good job, if you are incorrect it will state so and return you to the prompt (it won't let you continue until you get it right). Afterwards it will ask if you'd like to continue yes or no. If yes, Do loop back up to initial function to return another set of random numbers to multiply, wash, rinse, repeat.
For some reason my functions aren't working at all. You will see in the code I tried placing window.alerts just so I know its running through that particular function. Alas, no alert in either function. I know that all the code isn't here for what I'm trying to accomplish, I'm not necessarily looking for someone to write out the whole script (need to learn it myself) but functions will not work. Syntax? Any help is appreciated!
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
document.writeln ("<h2 style = 'color:blue' >");
document.writeln ("Hello! Are you ready to learn some multiplication?");
/* I don't believe either function is working properly and
I'm not entirely sure its syntax. I'm doin something wrong and
I'm gouging my eyes out!!! */
do {
function start() {
var button = document.getElementById("go");
button.addEventListener("click", fetchnumbers, false);
/* I add this to pop up during function 1 Just to check to see if its working*/
window.alert ("function 1");
}
function fetchnumbers() {
var math1 = Math.floor ((Math.random()*12)+1);
var math2 = Math.floor ((Math.random()*12)+1);
// I add this to pop up and display the numbers from the variables to ensure correct syntax for math function but heck no popup
window.alert (math1 + math2 );
}
finish = window.prompt ("Are we done for today?\n\nYes = 1\nNo = 2");
} while (finish == 2);
</script>
</head>
<body>
<br />
<br />
<form>
<input id="go" type="button" value="Yeah!">
<!--the id is referenced in the start function.-->
</form>
</body>
</html>