How can I make this piece of code work? 4/6


#1

I finished 4/6, but I kept getting "Error: unexpected label." I didn't understand why. This is what my code looked like.

var user = prompt ("You get to pick one of the three basic pokemon to fight Brock: BULBASAUR, SQUIRTLE or CHARMANDER. Which do you choose?").toUpperCase();

switch(user) {
case 'BULBASAUR':
console.log("BULBASAUR USED VINE WHIP. IT IS SUPER EFFECTIVE!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");
break;
case 'SQUIRTLE':
console.log("Excellent choice!");
console.log("SQUIRTLE USED WATER GUN. IT IS SUPER EFFECTIVE!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");
break;
case 'CHARMANDER':
var level = prompt ("This is an important battle. Have you trained him properly? What level is he?");
if (level < 16) {console.log("CHARMANDER USED EMBER. IT'S NOT VERY EFFECTIVE. ONIX TAKES HIM DOWN!");
console.log("Keep training, then try again!");}
else if (level isNaN) {console.log ("What did you say was his level? Try again!");}
else {console.log("CHARMANDER USED FLAMETHROWER. IT'S NOT VERY EFFECTIVE, YET ONIX GOES DOWN!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");}
break;
default:
console.log("You might have misspelled something, try again!");}

I found out that this was the problem:

case 'CHARMANDER':
var level = prompt ("This is an important battle. Have you trained him properly? What level is he?");
if (level < 16) {console.log("CHARMANDER USED EMBER. IT'S NOT VERY EFFECTIVE. ONIX TAKES HIM DOWN!");
console.log("Keep training, then try again!");}
else if (level isNaN) {console.log ("What did you say was his level? Try again!");}
else {console.log("CHARMANDER USED FLAMETHROWER. IT'S NOT VERY EFFECTIVE, YET ONIX GOES DOWN!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");}
break;

Afterwards, I changed my code to look like this, and it was accepted:

var user = prompt ("You get to pick one of the three basic pokemon to fight Brock: BULBASAUR, SQUIRTLE or CHARMANDER. Which do you choose?").toUpperCase();

switch(user) {
case 'BULBASAUR':
console.log("BULBASAUR USED VINE WHIP. IT IS SUPER EFFECTIVE!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");
break;
case 'SQUIRTLE':
console.log("Excellent choice!");
console.log("SQUIRTLE USED WATER GUN. IT IS SUPER EFFECTIVE!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");
break;
case 'CHARMANDER':
console.log("CHARMANDER USED EMBER. IT'S NOT VERY EFFECTIVE. ONIX TAKES HIM DOWN!");
console.log("Keep training, then try again!");
break;
default:
console.log("You might have misspelled something, try again!");}

So my question is, do you know what I could do to make my piece of code work? I tried making "level" a global variable, but that didn't work either. Any help would be appreciated. Thanks!

Also, in 6/6, I have noticed that using the options BRIBE and SNATCH, no matter what I do I get the the answer set to the && condition:

var user = prompt ("You get to pick one of the three basic pokemon to fight Brock: BULBASAUR, SQUIRTLE or CHARMANDER. Which do you choose? Otherwise, will you try to BRIBE him or SNATCH a badge and run away?").toUpperCase();

switch(user) {
case 'BULBASAUR':
console.log("BULBASAUR USED VINE WHIP. IT IS SUPER EFFECTIVE!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");
break;
case 'SQUIRTLE':
console.log("Excellent choice!");
console.log("SQUIRTLE USED WATER GUN. IT IS SUPER EFFECTIVE!");
console.log("ONIX HAS FAINTED! YOU HAVE DEFEATED BROCK AND HAVE EARNED A BADGE!");
break;
case 'CHARMANDER':
console.log("CHARMANDER USED EMBER. IT'S NOT VERY EFFECTIVE. ONIX TAKES HIM DOWN!");
console.log("Keep training, then try again!");
break;
case 'BRIBE':
var money = prompt ("Do you have money? True or False?").toLowerCase();
var woman = prompt ("Are you an attractive woman? True or False?").toLowerCase();
if (money && woman ){console.log("Brock looks around nervously. After a moment or two he asks not to mention it to anyone and sneaks a badge into the palm of your hand. Success!");}
else if (money || woman){console.log("Brock looks disappointed in you, and then asks you to leave his gym immediately.");}
else {console.log("Brock hands over a badge that unbeknowest to you, blacklists you from further participation in tournaments.");}
break;
case 'SNATCH':
var speed = prompt ("You are fast right? True or False?").toLowerCase();
var sneak = prompt ("You are sneaky, right? True or False?").toLowerCase();
if (speed && sneak) {
console.log("You stealthily take Brock's badge and make your way out without being noticed. Success! Just better hope these badges don't have any ID numbers on them, then you're in trouble!");}
else {
console.log("Brock catches up to you, restrains and reports you to the authorities for theft.");}
break;
default:
console.log("You might have misspelled something, try again!");}


#2

A gentle reminder isNaN(level) is correct usage.


#3

I just tried it, and it worked! Thank you!