这是我的代码。它说"期望一个标识符,而是看到' else'。缺少分号。"对于"其他"在 -
if(fight === "Fight");
{
alert("You Fought The Pikachu And Won!");
}
else
{
alert("You Ran From The Pikachu And Got Away To Saftey");
}
答案 0 :(得分:3)
从错误消息中可以明显看出,但if语句不以分号结尾。
替换
if(fight === "Fight"); // <- SYNTAX ERROR
{
alert("You Fought The Pikachu And Won!");
}
else
与
if(fight === "Fight")
{
alert("You Fought The Pikachu And Won!");
}
else
至于缩短,你可以开始删除不必要的开关/案例 - &gt; http://jsfiddle.net/adeneo/naNk9/