admin管理员组文章数量:1271758
I am learning Javascript via Codecademy and no have been stumped on this little piece here.
I have supposed to write an if else statement.
It shows me here in the following that there is a Syntac Error with a missing identifier:
var userAnswer = prompt("Are you feeling lucky, punk?");
if (userAnswer === "yes");
{
console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!");
}
else {
console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.");
}
What is wrong with that.... There is no error in this example here:
if (age < 18)
{
console.log("We take no actions or responsibility. Play at your own risk!");
}
else
{
console.log("Enjoy the game");
}
I am learning Javascript via Codecademy and no have been stumped on this little piece here.
I have supposed to write an if else statement.
It shows me here in the following that there is a Syntac Error with a missing identifier:
var userAnswer = prompt("Are you feeling lucky, punk?");
if (userAnswer === "yes");
{
console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!");
}
else {
console.log("You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.");
}
What is wrong with that.... There is no error in this example here:
if (age < 18)
{
console.log("We take no actions or responsibility. Play at your own risk!");
}
else
{
console.log("Enjoy the game");
}
Share
Improve this question
edited Nov 1, 2014 at 6:05
tshepang
12.5k25 gold badges97 silver badges139 bronze badges
asked Feb 1, 2014 at 16:18
user3260811user3260811
231 gold badge1 silver badge3 bronze badges
1
- 2 It would be easier to debug, if you'd use remended code conventions for JS. – Teemu Commented Feb 1, 2014 at 16:25
4 Answers
Reset to default 4if (userAnswer === "yes");
Remove the semicolon.
There's a semi-colon after the first conditional check. Also, you should always put the opening bracket of the conditional branch on the same line as the brackets
var age;
age = prompt('How old are you?');
if (age < 18)
{
alert("We take no actions or responsibility. Play at your own risk!");
}
else if(age > 18)
{
alert("Enjoy the game");
}
remove the semicolon after
if (userAnswer === "yes");
if you put the semicolon there, you are telling the script to stop there and not to render the next conditional statement that is "else"[SyntaxError: Unexpected token else]
本文标签: javascriptSyntax Error Unexpected token ElseStack Overflow
版权声明:本文标题:javascript - Syntax Error: Unexpected token Else - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741078899a2335797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论