你好,我试图制作一个"选择你自己的冒险"游戏,但我收到这个错误。 我似乎无法弄清楚如何解决这个问题,任何帮助将不胜感激这是我到目前为止的编码,
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");
}
我鼓励你在论坛上做更多的研究,这样你就可以了解如何做事。致力于清理代码。如果一开始不起作用,请不要气馁。