[Solved] expected an identifier but instead found ‘else’ [closed]


You should not have a semi-colon after the last else.

Consider the order of your answers. Suppose you want the user to be sent directly to the game when userawnser == 1 (aka true). If userawnser == 2 (aka “User exits the door”), then the code should notify the user that they cannot play.

Try my code snippet below:

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

I encourage you to do more research on forums, so that you can understand how to do things. Dedicate yourself to clean-up your code. Do not get discouraged if it does not work at first.

solved expected an identifier but instead found ‘else’ [closed]