Javascript 应为标识符,但却找到了';其他';
你好,我想做一个“选择你自己的冒险”游戏,但我得到了这个错误。我似乎不知道如何解决这个问题,任何帮助都将不胜感激 这是我到目前为止的编码Javascript 应为标识符,但却找到了';其他';,javascript,debugging,Javascript,Debugging,你好,我想做一个“选择你自己的冒险”游戏,但我得到了这个错误。我似乎不知道如何解决这个问题,任何帮助都将不胜感激 这是我到目前为止的编码 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
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
(akatrue
)时将用户直接发送到游戏。如果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");
}
var age=prompt(“你多大了?”);
var-userawnser;
//----------------------------------------------
//答案>=10
如果(年龄>=10岁){
警惕(“您可以继续”);
警惕(“你在一个小房间里,坐在一张桌子上。你身后有一扇门。请注意,世界末日刚刚开始。你的大楼里只有几个活着的人在考虑寻找武器”);
userawnser=prompt(“您是“键入1”以“检查房间”还是“键入2”通过门退出?”);
if(userawnser==1){
警告(“你看到桌上有订书机,在“输入代码”旁边有一只球棒,或者是一台电脑。你抓住球棒”);
}else if(userawnser==2){
警惕(“你走出房间,受到僵尸的突然袭击”);
警惕(“你试图让僵尸离开,但因为它让你感到意外,你被咬在脖子后面,加入了不死军团”);
}否则{
提醒(“对不起,您选择的号码是什么?”);
}
var confirmNeverGo=confirm(“永远不要去没有保护的地方,否则你的内脏会再次被收获!”);
if(confirmNeverGo==false){
警觉(“那以后就没有了!”);
}
//------------------------------------------------------------------
//回答你有一个打字错误(额外的;
在之后,其他的)。你的代码还有很多其他的问题,比如使用=
而不是=
(这会破坏整个过程),严重缺乏缩进,任意空白,等等。我建议你去找一个好的。在测试相等性时使用=
,而不是=
。不要把;
放在else
或if
语句中的test子句后面。这没有任何原因!
-是的,没错。