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

Tell us what’s happening:

This is my code, but i keep getting errors. Struggled with it for almost an hour, close to giving up the whole lesson.
function update(location) {
button1.innerText = location[“button text”][0];
button2.innerText = location[“button text”][1];
button3.innerText = location[“button text”][2];
button1.onclick = location[“button functions”][0];
button2.onclick = location[“button functions”][1];
button3.onclick = location[“button functions”][2];

Your code so far

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

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

function update(location) {
  button1.innerText = location["button text"][0];
  button2.innerText = location["button text"][1];
  button3.innerText = location["button text"][2];
  button1.onclick = location["button functions"][0];
  button2.onclick = location["button functions"][1];
  button3.onclick = location["button functions"][2];
  text.innerText = "You are in the town square. You see a sign that says \"Store.\"";
}

// 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/133.0.0.0 Safari/537.36

Challenge Information:

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

This passes for me. I would reset the lesson and use these exact the 3 lines. You may have a stray change outside of the editable region.

1 Like

There looks like an issue with the end of this string, concentrate on the double quotes.

 text.innerText = "You are in the town square. You see a sign that says \"Store.\"";
1 Like

Thank you for replying, i tried it, but it still says I am doing something wrong. Could this be a bug? I also noticed a typo in the default text given at step 67 -

function update(location) {
  button1.innerText = location["button text"][0];
  button2.innerText = location["button text"][1];
  button3.innerText = location["button text"][2];
  button1.onclick = goStore;
  button2.onclick = goCave;
  button3.onclick = fightDragon;
  text.innerText = "You are in the town square. You see a sign that says \"Store.\"";
}

Like you said, it should end in ". ";}

Yes, there is a bug in your code. I would reset it and only change the 3 lines the instructions talk about.

1 Like

I restarted but it still didnt work, but when i went one step back and redid everything, it worked without problems. Thank you so much for all the help. I was actually wondering something that is a bit unclear for me. The constant locations is basically an array composed of two objects if im not mistaken. Both objects have similar descriptions, like "button functions", text and so on. Shouldnt the correct way to select it be location[1][“button functions”][0] ? The way i`m thinking is that i need to select the second object in the array, and then the first function in “button functions”. I apologize if it is a stupid question, just trying to figure out how JS works.

it depends on what value is given to the location parameter

if the function update would be called with update(locations) then you would be right, but it will not be this. Check your goTown function to see how update is called

1 Like