需要一个标识符,但却找到了 'else'

expected an identifier but instead found 'else'

你好,我正在尝试制作 "choose your own adventure" 游戏,但出现此错误。我似乎无法弄清楚如何解决这个问题,我们将不胜感激 这是我目前的编码,

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(又名 "User exits the door"),则代码应通知用户他们不能玩。

试试下面我的代码片段:

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");
}

我鼓励您在论坛上做更多的研究,这样您就可以了解如何做事。致力于清理代码。如果一开始不起作用,请不要气馁。