javaScript初学者:简单的函数调用

时间:2014-11-04 08:34:42

标签: javascript

大家好我刚刚来这里也是初学者学习javascript ... 我现在有一个问题是从函数start()调用函数 当我选择级别和算术运算时,它将以函数start()开始 然后两个变量将保存... 但问题是无法调用下一个函数level()和operation() 我可以知道这是什么问题吗? 是否有>>的错误if(levelselect ==" 1")以及if(operationselect ==" add")选择那部分...感谢帮助我



<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();
    }
}
	

</script>

<
&#13;
<!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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

你有'&lt;'在js结束时打开。 检查功能在哪里? 你还需要纠正身体标签: 你的js在哪里?在一个文件?还是头脑?