You'll have to forgive me, I'm new to JavaScript...like a few weeks new. Anyway, I created a code using JavaScript to generate two random numbers, ask to add them, and give a "That is correct/that is incorrect" answer based on the users response. I wanted to add the other signs (-,*,/) to the equation and decided to try my hand at arrays to do so. Here is what I have so far:
<head>
<meta charset="utf-8" />
<title>Math Games</title>
</head>
<body>
<script>
var Answer;
var numbers=new Array();
var signs=new Array();
var Signs2=new Array();
var SignNoQuote=new Array();
numbers[0]=(Math.floor(Math.random() * 10 + 1));
numbers[1]=(Math.floor(Math.random() * 10 + 1));
signs[0]="+";
signs[1]="-";
signs[2]="*";
signs[3]="/";
SignNoQuote[0]="+";
SignNoQuote[1]="-";
SignNoQuote[2]="*";
SignNoQuote[3]="/";
Signs2[0]=(Math.floor(Math.random() * 4));
Answer=window.prompt("What is " + numbers[0] + signs[Signs2[0]] + numbers[1] + "?");
if(Answer==numbers[0] + SignNoQuote[Signs2[0]] + numbers[1])
{
window.alert("That's Correct!");
}
else
{
window.alert("That is Incorrect");
}
</script>
<a href="file:///E:/ECS/Legitimate%20Work/mathtest.html">Refresh</a>
</body>
It asks the question correctly, but when the right answer is given, it says that it is incorrect. I tried removing the quotation marks from the values of the "SignNoQuote" array hoping it would work, but when it is run that way, none of the script will run and the debugger claims it to be a syntax error? What am I doing wrong and how can I fix it?