Need help with code


#1

Hello. I am trying to run a partially finished game that I made. However, when I start running my program, it says: SyntaxError: Unexpected token =. I don't know where or what it is talking about. Please help. Thanks! Link to lesson:
https://www.codecademy.com/courses/javascript-beginner-en-NhsaT/2/5?curriculum_id=506324b3a7dffd00020bf661

This is my code:

var gameconfirm = prompt("Are you ready to play RPG Simulator? (yes or no)");
if (gameconfirm === "yes") {confirm("Alright, please answer the following. Thanks.");}
else {confirm("That's unfortunate. Come back next time! (Your journey is now at an end)"); window.stop();}
var name = prompt("What's your name, traveler?");
var gender = prompt("What's your gender, traveler? (male or female)");
if (gender === "male") {gender = "He";}
else if (gender === "female") {gender = "She";}
else {confirm("You did not enter a valid gender. Your journey is at an end.");  window.stop();}
var class = prompt("What is your class? (knight, archer, or wizard)");
var weapon = "TO BE CHOSEN"
if (class === "knight") {weapon = "sword"}
else if (class === "archer") {weapon = "bow"}
else if (class === "wizard") {weapon = "magic"}
else {confirm("You did not enter a valid class. Your journey is at an end.");  window.stop();}
console.log("Alright, " + name + "." + " Your journey is about to begin! Stay safe out there, and don't die...");
confirm("Your journey has now begun!");
//Note to self.     name = the person's name, gender = He/She in caps, class = class (wizard, archer etc.) in lowercase, weapon = weapon (sword, bow, magic) in lowercase.
console.log(" It is the year 20XX. There once was a " + class + " named " + name + ".");
confirm("Next");
console.log(gender + " lived in a world where humans were threatened by evil robots.");
confirm("Next");
console.log("One day, " + name + " realized that it would be better to destroy the source of the robots, instead of trying to defend villages against them.");
confirm("Next");
console.log(gender + " gathered supplies in preparation for the long journey that would await.");
confirm("Next");
console.log("A few hours has passed." + name + " encounters a fork on the road. There are 2 signs. The one on the left says: DO NOT ENTER. The one on the right says: THIS IS THE SAFE ROUTE.");
confirm("Next");
var fork = prompt("Which direction will " + name + " take? (left or right)");
//I am temporarily going to stop working on this so I can get help on where my Syntax error is.

#2

@websolver58853
You are using a reserved-keyword =class= (changed it into cclass)
There is no shuch thing as a windows.stop() in Javascript.....
also
changed the IF ELSE structure .....

var gameconfirm = prompt(
    "Are you ready to play RPG Simulator? (yes or no)");
if (gameconfirm === "yes") {
    confirm("Alright, please answer the following. Thanks.");
    var name = prompt("What's your name, traveler?");
    var gender = prompt("What's your gender, traveler? (male or female)");
    if (gender === "male") {gender = "He";}
    else if (gender === "female") {gender = "She";}
    else {
        confirm("You did not enter a valid gender. "+
        "Your journey is at an end.");  
        //window.stop();
        }
    var cclass = prompt("What is your class? (knight, archer, or wizard)");
    var weapon = "TO BE CHOSEN";
    if (cclass === "knight") {weapon = "sword";}
    else if (cclass === "archer") {weapon = "bow";}
    else if (cclass === "wizard") {weapon = "magic";}
    else {
        confirm("You did not enter a valid class. "+
        "Your journey is at an end.");  
        //window.stop();
        }
    console.log("Alright, " + name + "." + 
                " Your journey is about to begin! "+
                "Stay safe out there, and don't die...");
    confirm("Your journey has now begun!");
//Note to self.     name = the person's name, gender = He/She in caps, 
//cclass = cclass (wizard, archer etc.) in lowercase, 
//weapon = weapon (sword, bow, magic) in lowercase.
    console.log(
        " It is the year 20XX. There once was a " + 
        cclass + " named " + name + ".");
    confirm("Next");
    console.log(gender + 
    " lived in a world where humans were threatened by evil robots.");
    confirm("Next");
    console.log("One day, " + name + 
                " realized that it would be better to destroy the "+
                "source of the robots, instead of trying to defend "+
                "villages against them.");
    confirm("Next");
    console.log(gender + " gathered supplies in preparation for the "+
                "long journey that would await.");
    confirm("Next");
    console.log("A few hours has passed." + name + 
                " encounters a fork on the road. There are 2 signs. "+
                "The one on the left says: DO NOT ENTER. "+
                "The one on the right says: THIS IS THE SAFE ROUTE.");
    confirm("Next");
    var fork = prompt("Which direction will " + name + 
                      " take? (left or right)");
//I am temporarily going to stop working on this so 
//I can get help on where my Syntax error is.
}
else {
    confirm("That's unfortunate. Come back next time! "+
    "(Your journey is now at an end)"); //window.stop();
    }

Have a look at the =reserved-keywords=
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar


#3

Thank you so much! I did not know class was a reserved keyword. I also learned about a few errors I made. You really helped. Thank you!