意外的令牌,否则javascript

时间:2013-03-29 12:46:27

标签: javascript google-chrome

所有其他语句都会产生意外的令牌错误

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);

3 个答案:

答案 0 :(得分:4)

首先(不是语法错误,但无论如何都是错误的):使用==代替=进行比较。

您的语法错误是您在if块之后使用; - 删除它们。

答案 1 :(得分:2)

意外令牌错误是因为您使用};结束了其他人,但应该只有}

答案 2 :(得分:0)

if (start = true)替换为if (start == true)。并且};但应该只有}

相关问题