无法使用firefox在浏览器中运行此代码

时间:2015-03-21 21:43:18

标签: javascript function loops

试图让这个代码在更加柔和的情况下运行我保存它,当我尝试打开它没有任何反应时我看不到提示框任何帮助将不胜感激。我正在使用开关尝试弹出提示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<script type="text/javascript">

var secretNumber = prompt("Pick a number between 1 and 5:", "");
secretNumber = parseInt(secretNumber);

switch (secretNumber)
{
case 1:
    document.write("Too low!");
    break;

case 2:
    document.write("Too low!");
    break;

case 3
    document.write("You guessed the secret number!");
    break;

case 4
    document.write("Too high!");
    break;

case 5 
    document.write("Too high!");
    break;

default:
    document.write("you did not enter a number between 1 and 5!");
    break;
}
document.write("<br />Execution continues here");

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

1 个答案:

答案 0 :(得分:2)

在案例3-5中,您忘记了交换机中的:字符。这是工作代码:

var secretNumber = prompt("Pick a number between 1 and 5:", "");
secretNumber = parseInt(secretNumber);

switch (secretNumber)
{
case 1:
    document.write("Too low!");
    break;

case 2:
    document.write("Too low!");
    break;

case 3:
    document.write("You guessed the secret number!");
    break;

case 4:
    document.write("Too high!");
    break;

case 5:
    document.write("Too high!");
    break;

default:
    document.write("you did not enter a number between 1 and 5!");
    break;
}
document.write("<br />Execution continues here");