Step 46 Learn Basic Javascript by building a role playing game

In Step 46 of Learn basic Javascript by building a role playing game it says

Step 46

Now you need to modify your display text. Change the innerText property of the text to be You enter the store.. However text is defined as const so it cannot be changed.

const text = document.querySelector(“#text”);

Your instruction is very vague and I have not seen a answer from the other posts that satisfactorily answers this question. Exactly where do I enter this code.

text is a variable that you initialized near the top of your code in a previous step:

const text = document.querySelector("#text");

You want to set the innerText property of this variable to “You enter the store.”. Similar to how you changed the innerText property of the three buttons.

1 Like

It’s defined as a const and cannot be changed.

When a const variable holds an object or an array that means you can’t set it to another object or array, but you can still change the values and properties inside of the object or array.

const myArray = [1, 2, 3];
myArray.push(4); // you can do this
myArray[0] = 5; // you can do this
myArray = ['a', 'b', 'c']; // you can't do this

I know const makes it sound like you can’t change anything, but you just can’t change the actual object or array it is pointing to. You can still change what’s inside of the object or array.

That’s why you were able to set the innerText property on the three buttons in previous steps even though they are declared with const too.

1 Like

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