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

Tell us what’s happening:

i am not getting the point that" set “button text” to an array with three “Go to town square” strings, set “button functions” to an array with three goTown variables, " where i am getting wrong with this code

Your code so far

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

/* file: styles.css */

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

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":["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"],
    "button functions":[goStore, goCave, fightDragon],
    text:"The monster screams Arg! as it dies. You gain experience points and find gold."
  }
];

// User Editable Region

Your browser information:

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

Challenge Information:

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

Hi there! What’s the problem? You simply have to create an arrays with three identical values:

"button text": ["string",  "string", "string"],
"button functions": [variable, variable, variable],

“button text”:[“Buy 10 health (10 gold)”, “Buy weapon (30 gold)”, “Go to town square”],
“button functions”:[goStore, goCave, fightDragon], identical strings

but i have checked every thing even with this “{
name:“kill monster”,
“button text”: [“Go to store”, “Go to cave”, “Fight dragon”],
“button functions”:[goStore, goCave, fightDragon],
text:“The monster screams Arg! as it dies. You gain experience points and find gold.”
}”

Ok, look at the instructions again:

set "button text" to an array with three "Go to town square" strings,
set "button functions" to an array with three goTown variables

Hence you have to use only this string "Go to town square" and only this variable goTown

thank you but can you please explain why dont we use one “Go to town square” instead of three
why we are using 3 goTown functions what happens with this code

You’re welcome. We have three buttons on every step of this game and instead of removing or hiding buttons we’re setting them to do the same functions on the “kill monster” page, I think this decision was taken for simplicity sake

1 Like

thank you for the explanation

1 Like