期望一个标识符,但找到了“else”
expected an identifier but instead found 'else'
你好,我试图制作一个"选择你自己的冒险"游戏,但我收到这个错误。 我似乎无法弄清楚如何解决这个问题,任何帮助将不胜感激这是我到目前为止的编码,
var age = prompt("how old are you?");
if (age > 10) {
alert("you may proceed");
} else; {
alert("I think you should leave, NOW");
}
alert(
"you are in a small room sitting in a desk. there is a door right behind you PLEASE NOTE the apocalypses has just started there are only a few people in your building alive think about finding a weapon"
);
var userawnser = prompt(
"Do you 'type 1 to' examine the room or '2' exit through the door?"
);
if (userawnser = 1) {
alert(
"You see a stapler on your desk a bat by the door and a computer.You grab the bat"
);
} else if (userawnser = 2); {
alert(
"you walk outside of you room and are surprise attacked by a zombie"
);
alert(
"you attempt to get the zombie off but since it got you by surprise you are bitten in the back of the neck and join the undead army"
);
confirm(
"never go places unprotected silly or your guts will be harvested again!"
);
} else; {
alert("that doesn't make any since!");
}
最后一个else
之后不应该有分号。
考虑一下答案的顺序。假设您希望在userawnser == 1
时将用户直接发送到游戏(也称为 true
)。如果userawnser == 2
(又名"用户退出门"),则代码应通知用户他们无法玩游戏。
试试下面的代码片段:
var age = prompt("how old are you?");
var userawnser;
//----------------------------------------------
//answer >=10
if (age >= 10) {
alert("you may proceed");
alert("you are in a small room sitting in a desk. there is a door right behind you PLEASE NOTE the apocalypses has just started there are only a few people in your building alive think about finding a weapon");
userawnser = prompt("Do you 'type 1 to' examine the room or '2' exit through the door?");
if (userawnser == 1) {
alert("You see a stapler on your desk a bat by the do`enter code here`or and a computer.You grab the bat");
} else if (userawnser == 2) {
alert("you walk outside of you room and are surprise attacked by a zombie");
alert("you attempt to get the zombie off but since it got you by surprise you are bitten in the back of the neck and join the undead army");
} else {
alert("Sorry, what number you choice?");
}
var confirmNeverGo = confirm("never go places unprotected silly or your guts will be harvested again!");
if (confirmNeverGo === false) {
alert("that doesn't make any since!");
}
//------------------------------------------------------------------
//answer <=10(poor kid)
} else {
alert("I think you should leave, NOW");
}
我鼓励你在论坛上做更多的研究,这样你就可以了解如何做事。致力于清理代码。如果一开始不起作用,请不要气馁。
相关文章:
- 如果在对象上触发了dispatchEvent,我如何才能找到如何侦听它以及在哪里调度事件
- 我可以在客户端上找到在收听提交事件时按下了哪个提交按钮吗?
- 我如何找到'我的代码出了问题
- 我找到了那张桌子,但却找不到;无法获取ID
- 期望一个标识符,但找到了“else”
- Javascript 缩短了 if 语句添加 else 语句
- 为什么递归单词搜索求解器缺少五个单词,却找到了其他 47 个单词
- Jquery ajax 给了我一个 404 未找到错误
- Facebook找到了一种解决移动滚动的方法
- JavaScript: else 语句在 for.in 循环中破坏了我的 if 语句
- 嵌套的 if/else 语句讨论了分配变量.我已经这样做了,但它仍然不起作用
- 在javascript中找到了这行代码.它是什么样的加密
- 无法't更新流星中的文档,找到了修复程序,但没有;I don’我不知道怎么用.我该把它放在哪里
- 期望一个标识符,却看到了'else'
- Undefined不是函数,即使找到了一个表单
- 在jquery源码中找到了这个,它是如何工作的
- Else返回语句掩盖了Else if返回语句
- 我找到了类似 lessc 的 javascript 组合器/编译器
- 我在文本/模板 javascript 脚本中找到了一些标签,但我不确定它们是什么
- 为什么我的文件在我的本地环境中找到,但在我的cpanel服务器上找到了404