打开时加载空白页

时间:2016-03-15 21:20:28

标签: javascript

我正在看一些简单的Javascript,有人可以帮助识别出错了,我是JS的新手,所以我确信它很简单,我错过了但是当我加载页面时,它会停留空白,什么都没有?

非常感谢任何帮助。

<!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>
    <script>


                var numx = prompt("enter your first number");
                var numy = prompt("enter your second number");
                var oper = prompt("enter one of the following operations you would like done to your two numbers, +, -, /, *");
                var answer = 0;

                if(oper == "+")
                {
                    answer = (numx + numy);
                }
                else if(oper == "-")
                {
                    answer = (numx - numy);
                }
                else if(oper == "*")
                {
                    answer = (numx * numy);
                }
                else (oper == "/")
                {
                    answer = (numx / numy);
                }
                document.write("<p>the answer is " + answer "</p>");

    </script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

document.write("<p>the answer is " + answer + "</p>");

这里是一个写入现有文档元素而不是document.write的小提琴。 https://jsfiddle.net/49yuod7w/