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

Tell us what’s happening:

It’s displaying and behaving correctly in the preview, but it’s not accepting my code. I’ve tried giving the text property to locations outside the curly braces, as a separate element in the array locations as well, with/without the parentheses after goTown, without the goTown function, with the text property as a string, and I’ve checked my capitals. I’m not sure what else I can do

Your code so far

/* User Editable Region */

const locations = [
    {
        name: "town square",
        "button text": ["Go to store", "Go to cave", "Fight dragon"],
        "button functions": [goStore, goCave, fightDragon],
        text: goTown().innerText 
    }
];

/* User Editable Region */

oh, and with “goTown().text.innerText” with/without the goTown in there

the problem lies in your text property the goTown variable is meant to be the value of the text property and don’t forget to use the ‘=’ operator

innerText is meant to be used to call the text property in the text not on the value goTown

I appreciate your help.

So it says to give text the value from the goTown function; i’ve changed the colon to an equals, but not sure to assign the value without calling it from the function? does it still go in the ‘location’ array?

Please post your updated code

I know this isn’t correct, but it’s the base of what I’ve been changing little things to see if that works.

const locations = [
    {
        
        name: "town square",
        "button text": ["Go to store", "Go to cave", "Fight dragon"],
        "button functions": [goStore, goCave, fightDragon]
        text = goTown().text.innerText;     
    }

];

This line can’t go inside the definition of your array.

it doesn’t want to take it outside the array either. either outside the braces or the brackets. The console says the locations property should have a text value, and that value should be the string " You are in the town square…" which does come up in the preview.

const locations = [
    text = goTown().text.innerText,
    {
        name: "town square",
        "button text": ["Go to store", "Go to cave", "Fight dragon"],
        "button functions": [goStore, goCave, fightDragon]
    }
];

also tried

const locations = [

    {
        name: "town square",
        "button text": ["Go to store", "Go to cave", "Fight dragon"],
        "button functions": [goStore, goCave, fightDragon]
    }
], text = goTown().text.innerText; 

for some reason

It’s still inside of the array. It must be completely outside of the [ and ]

it is on the second set of code i put in. i also tried it outside the braces but ahead of them

In the second code you put that line next to the ]

Put it on its own line

text.innerText should assign goTown variable you don’t need to add text.innerText to your variable it’s not necessary

tried with a comma and a semi colon after the ]. I’m also getting timed out on my replies, if it seems like i’m taking a while. I appreciate your patience and working me through this.

What exactly is it trying to achieve? why doesn’t take the text property like it takes the other properties?

const locations = 
 [
    {
        name: "town square",
        "button text": ["Go to store", "Go to cave", "Fight dragon"],
        "button functions": [goStore, goCave, fightDragon]
    }
], 
text = goTown().text.innerText;

It is much simpler.

It wants you to add a text property to the object inside the location array, and use the same string for the value as the one found in goTown on the right-hand side of the text.innerText. It just wants you to duplicate the same string value. There is nothing dynamic or evaluated going on just a hard-coded string in two places.

const arr = [
  {
    prop: "Some shared string"
  }
]

function fn() {
  DOMNode.property = "Some shared string"
}
1 Like

You don’t want the comma. Swap it for a semicolon.

wow thank you that was it. The instruction “Give this property the final text.innerText value from the goTown function.” really made me think i had to use the “text.innerText” ability.

1 Like

I agree, it is worded confusingly and we should try and clarify it.

Issue

can you post the updated code, please?

This does not look clean but it answers the question
text: “You are in the town square. You see a sign that says "Store".”