There's a problem with the 'PAY' option


Hi! I observed that the code the course shows at the beginning has a little problem. If you play the game and you choose ‘PAY’, but then when the game asks you if you have any money it continues on as if you’d have money. I modified the code so that it only asks you if you have troll dollars if you said that you have any money at all.

I hope what I just said makes sense to you all, but I guess most people observed that little error.

Anyway, here’s the modified code.

var troll = 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(troll) {
  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 {
      console.log("You're not strong OR smart? Well, if you were smarter, you probably wouldn't have tried to fight a troll. You lose!");
  case 'PAY':
    var money = prompt("All right, we'll pay the troll. Do you have any money (YES or NO)?").toUpperCase();
    if (money === "YES") {
    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 if (money === 'NO') {
      console.log("Why did you even choose pay?");
    } else {
      console.log("Dang! This troll only takes Troll Dollars. You get whomped!");
  case 'RUN':
    var fast = prompt("Let's book it! Are you fast (YES or NO)?").toUpperCase();
    var headStart = prompt("Did you get a head start?").toUpperCase();
    if(fast === 'YES' || headStart === 'YES') {
      console.log("You got away--barely! You live to stroll through the forest another day.");
    } else {
      console.log("You're not fast and you didn't get a head start? You never had a chance! The troll eats you.");
    console.log("I didn't understand your choice. Hit Run and try again, this time picking FIGHT, PAY, or RUN!");


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