好吧,這裏是我的代碼,任何人都知道如何解決這個問題?它甚至不會運行。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