好吧,这里是我的代码,任何人都知道如何解决这个问题?它甚至不会运行。Javascript语法错误:失踪)参数列表后:上列61
<!DOCTYPE html>
<html>
<head>
<title>Hiding Game</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="proj3.css" />
</head>
<body>
<script type="text/javascript">
var counter = 0;
document.writeln("<table>")
document.writeln("<th>Day</th>")
document.writeln("<th>Hiding Place</th>")
document.writeln("<th>Explosion</th>")
do{
counter = counter + 1
var hide = Number(prompt("It is day " + counter + ". Where will you hide (1, 2, 3, or 4)?"));
var explosionLocation = Math.floor(Math.random() * 4) + 1;
if (hide <1 || hide >4) {
alert("That is not a valid choice.")
}
else {
alert("Hiding place " + explosionLocation + " has exploded!")
if (hide !== explosionLocation) {
alert("You have survived!")
document.writeln("<tr><th>" + counter + "</th><td class='survived'>" + hide + "</td><td class='survived'>" + explosionLocation + "</td></tr>")
}
else {
alert("You have died. You survived for a total of " counter - 1 " days.")
document.writeln("<tr><th>" + counter + "</th><td class='died'>" + hide + "</td><td class='survived'>" + explosionLocation + "</td></tr>"")
document.writeln("<tr colspan='3'><td>"'Survived for ' + counter - 1 + ' days""</td></tr>")
}
}
} while (explosionLocation !== hide)
</script>
如果有人可以帮助将不胜感激。该代码应该生成一个游戏,用户试图避免死亡的几率为1/4。
您在该行末尾有错字。一个太多的引号。 – 2014-10-31 01:22:25
您应该学会解决您的代码问题。这是编程时你会一直在做的事情。如果您无法发现错误,请尝试在给定区域周围注释行,直到错误消失,然后仔细检查您的语法。 – 2014-10-31 01:24:24
我认为你应该尝试更多的难度,然后在这里发布你的问题 – 2014-10-31 01:24:33