2013-03-29 40 views
0

所有else语句意外的标记给出一个意外的标记错误其他的JavaScript

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

好故事! :-) – thejh

回答

0

if (start == true),而不是取代if (start = true)。而};但应该只是}

2

的意外标记错误是因为你最终的其他与};但应该只是}

+0

为了更准确,他结束了与他们的ifs。 – thejh

4

的第一件事情(而不是语法错误,但无论如何是错误的):使用==比较,而不是=

你的语法错误是你在if块后使用; - 删除那些。

+1

您应该用'==='替换'='以防止意外的类型转换进入。请参见:http://stackoverflow.com/a/359509/111219 –