What is wrong with the code


#1

why does this code not work and run

< console.log("You have now crossed the border or Dale and you will just need to head home. However, due to the fact that you have not been in Dale in over a decade, you are still confused where to go. On your right you see a small hut with a lonely old hag, on your left you see a jaw bridge leading to a small but dense forest.");
var user = prompt("Which direction do you want to go towards").toLowerCase();

switch(user) {
case "left":
var versatile = prompt("Are you versatile with the weapons you use ").toUpperCase();
var luck = prompt("Are you lucky")
if(versatile === 'yes'){
console.log("You manage to use a blade that you found stuck on a tree to cut your way through the dense forest");
}
else {
console.log("You could not find a way to go through so you head to the hags house but while crossing the jaw bridge, a few guards had found you and shot an arrow aiming at your knee, stopping you from moving. They then brought you back to jail");
}
break;
case 'right':
var luck = prompt('Are you lucky?').toUpperCase();
if(luck === 'YES'){
console.log('You managed to observe that the hag was unfriendly to strangers but you still decided to ask her where to go. At first she seemed hell bent on killing you, but she decided to tell you where the village you came from was.');
}
else{
console.log("She saw you coming near her cottage and she immediately cursed you and you became paralyzed!");
}
break;
}


#2

this is the whole code

console.log("You are wanted by the kingdom of Esgaroth.You have to escape the kingdom Esgaroth and return back to your homeland Dale. However, to do that,you would have to pass through the gate of Mirkwood.You will have to make a decision on what you are going to do to go through the gate of Mirkwood!If you make a mistake, you may very well bid farewell to the world...You are given 4 options. You can convince, bash your way through, run past them stealthily or go back to jail you are also required to assign 30 trade points to 7 traits respectively:strength,speed,versatality,intelligence,persuasion,agility,combat prowess and luck.the trait you assigned the most point to is you have to assign at least 5 to each trait that you are good at.")
    var user = prompt("What do you do?").toLowerCase();


switch(user) {
  case "convince":
    var smart = prompt("Are you smart?").toUpperCase();
    var persuasive = prompt("Are you persuasive?").toUpperCase();
    if(persuasive === 'YES'|| smart === 'YES') {
    console.log("The gatekeeper thought you looked similar to a criminal that he had seen escape the prison cells. However, You convinced the gatekeeper that you are innocent--nice work!");
        console.log("You have now crossed the border or Dale and you will just need to head home. However, due to the fact that you have not been in Dale in over a decade, you are still confused where to go. On your right you see a small hut with a lonely old hag, on your left you see a jaw bridge leading to a small but dense forest.");
var user = prompt("Which direction do you want to go towards").toLowerCase();


switch(user) {
  case "left":
    var versatile = prompt("Are you versatile with the weapons you use?").toUpperCase();
    var luck = prompt("Are you lucky?")
    if(versatile === 'yes'){
    console.log("You manage to use a blade that you found stuck on a tree to cut your way through the dense forest.");
    }
    else {
    console.log("You could not find a way to go through so you head to the hags house but while crossing the jaw bridge, a few guards had found you and shot an arrow aiming at your knee, stopping you from moving. They then brought you back to jail!");
    }
    break;
  case 'right':
    var luck = prompt('Are you lucky?').toUpperCase();
    if(luck === 'YES'){
    console.log('You managed to observe that the hag was unfriendly to strangers but you still decided to ask her where to go. At first she seemed hell bent on killing you, but she decided to tell you where the village you came from was.');
    }
    else{
    console.log("She saw you coming near her cottage and she immediately cursed you and you became paralyzed!");
    }
    break;       
}

    }

    console.log("You're neither persuasive or smart? Well, if you were smarter, you probably wouldn't have tried to convince the guard. You are on the run!");
    }
    break;
  case 'bash my way through':
    var strenght = prompt("Are you strong?").toUpperCase();
    var speed = prompt('Are you fast?').toUpperCase();
    if( strenght === 'YES' && speed === 'YES'){
    console.log('You slaughtered everyone there and managed to escape the area before the reinforcement arrived.');
            console.log("You have now crossed the border or Dale and you will just need to head home. However, due to the fact that you have not been in Dale in over a decade, you are still confused where to go. On your right you see a small hut with a lonely old hag, on your left you see a jaw bridge leading to a small but dense forest.");
var user = prompt("Which direction do you want to go towards").toLowerCase();


switch(user) {
  case "left":
    var versatile = prompt("Are you versatile with the weapons you use ").toUpperCase();
    var luck = prompt("Are you lucky")
    if(versatile === 'yes'){
    console.log("You manage to use a blade that you found stuck on a tree to cut your way through the dense forest");
    }
    else {
    console.log("You could not find a way to go through so you head to the hags house but while crossing the jaw bridge, a few guards had found you and shot an arrow aiming at your knee, stopping you from moving. They then brought you back to jail");
    }
    break;
  case 'right':
    var luck = prompt('Are you lucky?').toUpperCase();
    if(luck === 'YES'){
    console.log('You managed to observe that the hag was unfriendly to strangers but you still decided to ask her where to go. At first she seemed hell bent on killing you, but she decided to tell you where the village you came from was.');
    }
    break;
    else{
    console.log("She saw you coming near her cottage and she immediately cursed you and you became paralyzed!");
    }
    break;       
}

    


    }
    else{
    console.log("You were killed!");
    }
    break;
    case 'run past them stealthily':
    var armour = prompt('Are you wearing heavy armour?').toUpperCase();
    if(!armour === 'YES'){
    console.log("You were caught and thrown in jail!");
    }
    else{
    console.log("You slipped through their defence!");
    }
    break;
    default:
    console.log("They caught you while you were wasting your time formulating a plan. You were captured and sent to prison!")
    break;

    
    
}

#3

pls help any suggestions


#4

need else before it

 console.log("You're neither persuasive or smart? Well, if you were smarter, you probably wouldn't have tried to convince the guard. You are on the run!");
    }

should be like

else{
console.log("You're neither persuasive or smart? Well, if you were smarter, you probably wouldn't have tried to convince the guard. You are on the run!");
    }

and
remove break statement here

if(luck === 'YES'){
    console.log('You managed to observe that the hag was unfriendly to strangers but you still decided to ask her where to go. At first she seemed hell bent on killing you, but she decided to tell you where the village you came from was.');
    }
    break;  //remove break;

#5

thank you it is really helpfull


#6

helpful* i meant sorry


#7

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