简体   繁体   中英

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?

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. https://jsfiddle.net/49yuod7w/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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