Learn Basic JavaScript by Building a Role Playing Game - Step 173

Tell us what’s happening:

Step 173
Looking at your “kill monster” object, “button functions” currently has three goTown variables. Replace the third one with easterEgg - this is how a player will access the hidden feature of the game. Do not change the “button text”.

With this, your RPG game is complete! You can now play around - can you defeat the dragon?

Your code so far

<!-- file: index.html -->

/* file: script.js */
// User Editable Region

  {
    name: "kill monster",
    "button text": ["Go to town square", "Go to town square", "Go to town square"],
    "button functions": [goTown, goTown, goTown],
    text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.'
  },

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Basic JavaScript by Building a Role Playing Game - Step 173

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

Step 173

Looking at your "kill monster" object, "button functions" currently has three goTown variables. Replace the third one with easterEgg - this is how a player will access the hidden feature of the game. Do not change the "button text".

With this, your RPG game is complete! You can now play around - can you defeat the dragon?

{
  name: "kill monster",
  "button text": ["Go to town square", "Go to town square", "Go to town square"],
  // Updated the third button function from 'goTown' to 'easterEgg' to provide access to the hidden feature of the game.
  "button functions": [goTown, goTown, easterEgg], 
  text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.'
}

But I get this error message;
Sorry, your code does not pass. Hang in there.

You should update your fifth locations object to have a "button functions" property of [goTown, goTown, easterEgg].

you are missing a comma after the object

1 Like

Step 143

Add another object in the locations array. Everything should be the same as the lose object, except the name should be "win" and the text should be "You defeat the dragon! YOU WIN THE GAME! &#x1F389;".

const locations = [
  {
    name: "town square",
    "button text": ["Go to store", "Go to cave", "Fight dragon"],
    "button functions": [goStore, goCave, fightDragon],
    text: "You are in the town square. You see a sign that says \"Store\"."
  },
  {
    name: "store",
    "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"],
    "button functions": [buyHealth, buyWeapon, goTown],
    text: "You enter the store."
  },
  {
    name: "cave",
    "button text": ["Fight slime", "Fight fanged beast", "Go to town square"],
    "button functions": [fightSlime, fightBeast, goTown],
    text: "You enter the cave. You see some monsters."
  },
  {
    name: "fight",
    "button text": ["Attack", "Dodge", "Run"],
    "button functions": [attack, dodge, goTown],
    text: "You are fighting a monster."
  },
  {
    name: "kill monster",
    "button text": ["Go to town square", "Go to town square", "Go to town square"],
    "button functions": [goTown, goTown, easterEgg],  // Corrected: third button triggers easterEgg function
    text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.'
  },
  {
    name: "lose",
    "button text": ["REPLAY?", "REPLAY?", "REPLAY?"],
    "button functions": [restart, restart, restart],
    text: "You die. &#x2620;"
  },
  {
    name: "win",
    "button text": ["REPLAY?", "REPLAY?", "REPLAY?"],
    "button functions": [restart, restart, restart],
    text: "You defeat the dragon! YOU WIN THE GAME!
  }
];

Sorry, your code does not pass. Don’t give up.

You should have seven values in the locations array.

did you manage to solve this step or not?

No, the updated block of code with the seven values in the locations array gave me an error that I need to have seven values in the locations array.

wait, this is not step 173, you are now asking for step 143. Please use the HELP button to create a new topic.