0

すべての else ステートメントで予期しないトークン エラーが発生する

var men = 50;
alert("You are a Spartan warrior about to be fighting in the Trojan War, you get onto             your ship and set sail with a fleet of other ships but your ship breaks away from the others in a horrible storm! You have 50 men on your ship, do not lose more than 40 of them, or else.");
var start = confirm("are you ready to start?");
if (start = true) {
   alert("your platoon of Spartan soldiers is on a ship, headed for Troy");
}
else {
   alert("You failed in your mission and are executed in Sparta the next day (refresh the page)")
};
var hydra  = prompt("you encounter a large hydra on your journey to Troy, do you sail past it, or fight it?(fight or flee?)");
if (hydra = "fight") {
   alert("You kill the Hydra, but it has killed 8 of your men");
};
else {
   alert("You go around the Hydra, but it snatches up 6 of your men and starts to follow your ship!");
};
if (hydra = "fight") {
   men = 42
}
else {
   men = 44; 
};
console.log(men);
4

3 に答える 3

4

最初に (構文エラーではありませんが、とにかく間違っています):==の代わりに を使用して比較し=ます。

構文エラーは;、if ブロックの後に使用していることです。それらを削除してください。

于 2013-03-29T12:48:57.677 に答える
2

予期しないトークン エラーは、else を with で終了するためですが};}

于 2013-03-29T12:48:45.913 に答える
0

代わり if (start = true)に 置き換えif (start == true)ます。そして};、しかしあるべきです}

于 2013-03-29T12:48:29.367 に答える