What is wrong with my code


#1


Replace this line with your code. 

var user = prompt("Shall we play a game?").toUpperCase();
var user = prompt("Name please")
switch(user) {
case 'John':
    console.log("Nice name!!");
    break;
case 'Icabod':
    console.log("Your parents were satanic cultists, weren't they?");
    break;
case 'Willem':
        console.log("Best name on this list");
        break;
        case 'Jason':
            console.log("Great Name!!");
            break;
    default:
      console.log("Who are you?");
}
var player = prompt("Okay Let's start the game... Which class will you choose?").toUpperCase();
switch(player) {
    case 'Warrior':
        console.log("Nice choice! A good mix of offense and deffense!");
        break;
        case 'Archer':
            console.log("Okay a long range heavy hitter, be careful of their range! ");
            break;
            case 'Asassain':
                console.log("My personal favorite! Harness the power of illusions, stealth, and shadow, With powerful close quarters and stealth attacks! Enjoy!");
                break;
                case 'Mage':
                    console.log("......");
                    break;
                    default: 
                    console.log("Thats not a class!")
} var player = prompt("You walk through the forest and you stumble upon and sword with a dark feeling around it..... Will you pick it up?").toUpperCase();
switch(player) {
case 'Pick up the Sword':
    var brave = prompt("You look with greed flashing in your eyes will you pick up the sword(YES or NO)?").toUpperCase();
    var smart = prompt("You sense the feeling of dread and death around the sword and leave it to be claimed by a foolish explorer...Are you smart(Yes or No)?").toUpperCase();
    if(brave === "YES" || brave === "NO") {
    console.log("another victim is claimed by the death sword -- Game Over!");
    } else if (smart === "Yes") {
        console.log("you leave the sword be shivering with fright if you ever touched that blade....");
    } else {
        console.log("You die!!!");
    }
}


#2

I cannot find what is wrong with it


#3

Please, what error(s) are you getting?

Is this a comment?

If so, comment it out.

//Replace this line with your code.

And your code, then, looks good from here. :slight_smile:


#4

it says something is wrong with my syntax


#5

Have you effected the change I recommended?

If so, post new code.

Thank you! :slight_smile:


#6

i mistakenly added that here is my actual code it keeps saying there is a problem with your syntax

var tryAgain = function()
{
var input = prompt("would you like to play again enter YES or NO?").toUpperCase();
if(input === "YES")
{
game();
}
else if(input === "NO")
{
console.log("Thank you for playing,please visit again!");
}
else
{
alert("You have entered invalid option please enter YES or NO");
tryAgain();
}
};

var user = prompt("Shall we play a game?").toUpperCase();
var user = prompt("Name please")
switch(user) {
case 'John':
console.log("Nice name!!");
break;
case 'Icabod':
console.log("Your parents were satanic cultists, weren't they?");
break;
case 'Willem':
console.log("Best name on this list");
break;
case 'Jason':
console.log("Great Name!!");
break;
default:
console.log("Who are you?");
}
var player = prompt("Okay Let's start the game... Which class will you choose?").toUpperCase();
switch(player) {
case 'Warrior':
console.log("Nice choice! A good mix of offense and deffense!");
break;
case 'Archer':
console.log("Okay a long range heavy hitter, be careful of their range! ");
break;
case 'Asassain':
console.log("My personal favorite! Harness the power of illusions, stealth, and shadow, With powerful close quarters and stealth attacks! Enjoy!");
break;
case 'Mage':
console.log("......");
break;
default:
console.log("Thats not a class!")
} var game = function()
{
var user = prompt("You're walking through the forest, minding your own business, and you run into a troll! Do you FIGHT him, PAY him, or RUN?").toUpperCase();

switch(user)
{
case 'FIGHT':
var strong = prompt("How courageous! Are you strong(YES or NO)?").toUpperCase();
var smart = prompt("Are you smart?").toUpperCase();

 if(strong === 'YES' || smart === 'YES')
 {
  console.log("You only need one of the two! You beat the troll--nice work!");
 } 
else 
 {
   alert("You're not strong OR smart? Well, if you were smarter, you probably wouldn't                     have tried to fight a troll. You lose!");
   tryAgain();
 }

 break;

case 'PAY':
var money = prompt("All right, we'll pay the troll. Do you have any money (YES or NO)?" ).toUpperCase();

var dollars = prompt("Is your money in Troll Dollars?").toUpperCase();

if(money === 'YES' && dollars === 'YES')
{
console.log("Great! You pay the troll and continue on your merry way.");
}
else
{
alert("Dang! This troll only takes Troll Dollars. You get whomped!");
tryAgain();
};
}


#7

Okay.

You should close your game function with one curly bracket ( } ). At the end.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.