Im trying to make a simple math practice program in javascript. Different values are given in a prompt alert and the answer is compared with the user input. This is the code:
<html>
<head>
<title>Calculations</title>
<script language = "javascript">
generate();
function generate() {
{
var calc = Math.floor(math.random() * 3 + 1);
if (calc == 1){
calcSort == "+"
}else if(calc == 2){
calcSort == "*";
} else if (calc == 3){
calcSort == "/";
}
var num1 = Math.floor(Math.random() * 10 + 1);
var num2 = Math.floor(Math.random() * 10 + 1);
var answer;
if (calc == 1){
answer = num1 + num2;
} else if (calc == 2){
answer = num1 * num2;
} else if (calc == 3){
answer = num1 / num2;
}
var userAnswer = prompt("What is " + num1 + calcSort + num2 + "?");
if (userAnswer == answer){
alert("correct");
} else {
alert("fail");
}
}
</script>
</head>
</html>
The prompt doesn't appear, what's wrong?