Can someone help me on 3/6 lesson 10


#1

I tried using this code but it wont work it would be amazing if someone helped me
My Code
var man = prompt("You meet a wealthy man on your way to the nearest city. You don't have much money but he does.Do you pickpocket him,kill and loot him or do you leave him?");
switch(man) {
case 'pickpocket':
var stealth = prompt("How sneaky of you! Are you stealthy (YES or NO)?").toUpperCase();
var smart = prompt("Are you seen?").toUpperCase();
if(stealth === 'YES' || seen === 'no') {
console.log("You stole the man's money.HOW DARE YOU!");
} else {
console.log("You're not stealthy OR you're seen? Well, if you were sneakier, you probably wouldn't have been seen. You lose!");
}
break;
case 'kill and look':
var weapons = prompt("All right, we'll kill the man. Do you have any weapons (YES or NO)?").toUpperCase();
var armed = prompt("Is the man armed?").toUpperCase();
if(weapons === 'yes' && armed === 'no') {
console.log("Great! You kill the man and loot his body.");
} else {
console.log("Dang! This man is armed. You get whomped!");
}
break;
case 'leave':
var leave = prompt("Wanna leave him!").toUpperCase();
var turn back = prompt("Did you wanna try again?").toUpperCase();
if(leave === 'YES' || turn back === 'no') {
console.log("You didnt kill him or loot him you can go knowing you did something good.");
} else {
console.log("You're turning back to get his money to buy stuff.");
}
break;
default:
console.log("I didn't understand your choice. Hit Run and try again, this time picking pickpocket, kill, or leave!");
}


#2

you can't have a variable name with a space in it, replace your turn back with turn_back. spaces separate arguments, so you can't have them in a variable name


#3

it fixed that but it just plays the default log


#4

There is so much wrong with this code, i helped you to get it to run without an error, i can't do everything, here are some of the problems, you ask us to kill enter kill, and then your case is:

case 'kill and look':

of course that is not the same. In which case the default will run. Or this line:

if(stealth === 'YES' || seen === 'no') {

You don't have a seen variable (you do have a smart variable, but it is uppercase). You have a similar issue later in your code.


#5

here's
my new code and it still does that

var man = prompt("You meet a wealthy man on your way to the nearest city. You don't have much money but he does. Do you pickpocket him,kill and loot him or do you leave him?").toUpperCase();
switch(man) {
case 'pickpocket':
var stealth = prompt("How sneaky of you! Are you stealthy YES or NO?").toUpperCase();
var seen = prompt("Are you seen?").toUpperCase();
if(stealth === 'YES' || seen === 'no') {
console.log("You stole the man's money.HOW DARE YOU!");
} else {
console.log("You're not stealthy OR you're seen? Well, if you were sneakier, you probably wouldn't have been seen with your hand in his pocket. You lose!");
}
break;
case 'kill':
var weapons = prompt("All right, we'll kill the man. Do you have any weapons (YES or NO)?").toUpperCase();
var armed = prompt("Is the man armed?").toUpperCase();
if(weapons === 'yes' && armed === 'no') {
console.log("Great! You kill the man and loot his body.");
} else {
console.log("Dang! This man is armed. You get whomped!");
}
break;
case 'leave':
var leave = prompt("Wanna leave him!").toUpperCase();
var turn_back = prompt("Did you wanna try again?").toUpperCase();
if(leave === 'yes' || turn_back === 'no') {
console.log("You didn't kill him or loot him you can go knowing you did something good.");
} else {
console.log("You're turning back to get his money to buy stuff.");
}
break;
default:
console.log("I didn't understand your choice. Hit Run and try again, this time picking pickpocket, kill, or leave!");
}


#6

first line:

you convert to uppercase, and then your cases are lowercase, that is going to work (@not, in case the sarcasm isn't noticeable)


#7

Hi, just as @stetim94 has mentioned just a few minor tweaks are needed

var man = prompt("You meet a wealthy man on your way to the nearest city. You don't have much money but he does. Do you pickpocket him, kill and loot him or, do you leave him? Select one: (pickpocket/kill/leave)").toUpperCase();
// you have ented toUpperCase so all characters of a response entered into the 'man' variable through the prompt will be converted to into upperCase 
switch(man) {

case 'pickpocket': // this should be case 'PICKPOCKET':

var stealth = prompt("How sneaky of you! Are you stealthy YES or NO?").toUpperCase();
var seen = prompt("Are you seen?").toUpperCase();

if(stealth === 'YES' || seen === 'no') {  
    // change to upperCase 'NO'
console.log("You stole the man's money.HOW DARE YOU!");
} else {
console.log("You're not stealthy OR you're seen? Well, if you were sneakier, you probably wouldn't have been seen with your hand in his pocket. You lose!");
}
break;

case 'kill': // remember to change to upperCase

// remember to add three backticks before and after ur code (back tick key is next to no#1 key above the tab key on the left hand side of the keyboard

Ur a bit further ahead of me on this but shows us that its still all part of the learning identifying errors.

I got help earlier because I had entered 'N0' instead of 'NO'.....N0000000000000000000!!! haha.

When I posted the code for help and the error I too had made was shown me I cud've kicked myself lol.


#8

Thanks guys for helping me on this.