简体   繁体   English

打开时加载空白页

[英]Loading a blank page when opened

There's some simple Javascript I'm looking at, could someone please help identify what's wrong, I'm new to JS so I'm sure it's something simple that I've missed out but when I load the page, it stays blank and nothing loads? 我正在查看一些简单的Javascript,有人可以帮助您找出问题所在,我是JS的新手,所以我确定这很简单,我已经错过了,但是当我加载页面时,它保持空白并且什么都没有负载?

Any help is much appreciated. 任何帮助深表感谢。

<!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>

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

here's a fiddle that writes to an existing document element instead of document.write. 这是一个小提琴,它写入现有文档元素而不是document.write。 https://jsfiddle.net/49yuod7w/ https://jsfiddle.net/49yuod7w/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM