-4
嗨,所有即時新的這裏,也是初學者學習JavaScript ... 我有一個問題,現在是從函數調用函數開始() 當我選擇水平和算術運算,它將開始用功能啓動() 然後這兩個變量將被保存... 但問題是無法調用到下一個功能級別()和操作() 可能我知道是什麼問題? 難道我有錯誤>>如果(levelselect == 「1」),並且如果(operationselect == 「添加」)在選擇一部分...感謝幫助我javaScript初學者:簡單的函數調用
<script language="javascript">
var levelselect;
var operationselect;
var num1;
var num2;
var data;
var result;
function start(myForm) {
levelselect = myForm["level"].value;
operationselect = myForm["operation"].value;
level();
}
function level() {
if (levelselect == "1") {
num1 = (Math.floor(Math.random() * 9 + 1));
num2 = (Math.floor(Math.random() * 9 + 1));
operation();
} else if (levelselect == "2") {
num1 = (Math.floor(Math.random() * 90 + 10));
num2 = (Math.floor(Math.random() * 90 + 10));
operation();
} else if (levelselect == "3") {
num1 = (Math.floor(Math.random() * 900 + 100));
num2 = (Math.floor(Math.random() * 900 + 100));
operation();
}
}
function operation() {
if (operationselect == "add") {
data = window.prompt(+num1 + " + " + num2 + "?", "0");
result = parseInt(data);
check();
} else if (operationselect == "sub") {
data = window.prompt(+num1 + " - " + num2 + "?", "0");
result = parseInt(data);
check();
} else if (operationselect == "div") {
data = window.prompt(+num1 + "/" + num2 + "?", "0");
result = parseInt(data);
check();
} else if (operationselect == "mul") {
data = window.prompt(+num1 + " * " + num2 + "?", "0");
result = parseInt(data);
check();
}
}
\t
</script>
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Assignment 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>body>
<form id="form1" name="form1" method="post" action="" onsubmit="start(this);return false;">
<table align="center">
<tr align="center">
<td>
<label>Choose your Level :</label>
<select id="level">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr align="center">
<br>
<br>
<br>
<td>
<label>Choose your arithmetic operations :</label>
<select id="operation">
<option value="add">Addition</option>
<option value="sub">Subtraction</option>
<option value="div">Division</option>
<option value="mul">Multiplication</option>
</select>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Generate question" />
</td>
</tr>
</table>
</form>
</body>
</html>