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

Please help me - Java Script: Role Playing Game Step 63

Inside the update function, change the value of the button1.innerText assignment to be location["button text"] . That way, you use bracket notation to get the "button text" property of the location object passed into the function.

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."
  }
];

function update(location) {
  button1.innerText = "Go to store";
  button2.innerText = "Go to cave";
  button3.innerText = "Fight dragon";
  button1.onclick = goStore;
  button2.onclick = goCave;
  button3.onclick = fightDragon;
  text.innerText = "You are in the town square. You see a sign that says \"Store\".";
}

I don’t see your code changes. The code you pasted above is the default code. You need to do the following:

“…change the value of the button1.innerText assignment to be location["button text"].”

Please try to do that and if it doesn’t pass then paste your updated code in here so we can see what you did. Or if you don’t understand the instructions, please let us know what you don’t understand.

Hello bbsmooth,

If i am right then “location” is means to “locations”. And there are two button text arrays with value.

So I don’t understand how to change.

The locations array is an array of objects, each object representing a location, such as “town square” or “store”. The update function takes one of these location objects as an argument. For example, in the goTown function, the update function is called as follows:

update(locations[0]);

It is passing in the first item in the locations array, which is the “town square” object.

The update function is defined as:

function update(location) {

This means that the location object passed into the function will be named location inside of the function body, but it is still the same object that was passed into the function.

Basically, locations[0] and location are different names for the same object. So if you make a change to location inside of the update function, you are really making a change to locations[0].

location[“button text”][0];

it is working thanks

1 Like

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