Step 45 - Learn Basic JavaScript by Building A Role Playing Game

Hi i am struggling with this bit here.

function goStore() {
  button1.innerText = "Buy 10 health (10 gold)";
  button2.innerText = "Buy weapon (30 gold)";
  button3.innerText = "Go to town square";
  button1.onclick = buyHealth;
  button2.onclick = buyWeapon;
  button3.onclick = goTown;
  button1.innerText = "You enter the store";
}

what issue are you having? we need more context

Hi @up695407

Now you need to modify your display text. Change the innerText property of the text to be "You enter the store." .

The variable is text
The string needs a dot at the end of the sentence.

For next time, describe the issue in your own words. Learning to communicate problems is a part of becoming a web developer.

Happy coding

one thing i don’t understand is which text needs to be changed.

The element #text is selected on line 12 and saved in a variable named text, you need to change the innerText of this one

i still don’t understand

You need a dot . after “store” text in the text.innerText .

You already set the text of button1 on the first line of your goStore function.

For the code shown in the block below, you need to change button1 to the variable named text. Which @ILM mentioned above.

If you still have problems, please post your full code.

Use the following method to post code to the forum:

  1. On a separate line type three back ticks.
  2. On a separate line paste your code.
  3. On the last line type three back ticks. Here is a single back tick `

Happy coding

this is my full javascript code

let xp = 0;
let health = 100;
let gold = 50;
let currentWeapon = 0;
let fighting;
let monsterHealth;
let inventory = ["stick"];

const button1 = document.querySelector('#button1');
const button2 = document.querySelector("#button2");
const button3 = document.querySelector("#button3");
const text = document.querySelector("#text");
const xpText = document.querySelector("#xpText");
const healthText = document.querySelector("#healthText");
const goldText = document.querySelector("#goldText");
const monsterStats = document.querySelector("#monsterStats");
const monsterName = document.querySelector("#monsterName");
const monsterHealthText = document.querySelector("#monsterHealth");

// initialize buttons
button1.onclick = goStore;
button2.onclick = goCave;
button3.onclick = fightDragon;

function goStore() {
  button1.innerText = "Buy 10 health (10 gold)";
  button2.innerText = "Buy weapon (30 gold)";
  button3.innerText = "Go to town square";
  button1.onclick = buyHealth;
  button2.onclick = buyWeapon;
  button3.onclick = goTown;
}

function goCave() {
  console.log("Going to cave.");
}

function fightDragon() {
  console.log("Fighting dragon.");
}```

The challenge wants you to add one line of code here

The lesson wants you to update the text to say "You enter the store."

here is the basic syntax for using the innerText property

variableName.innerText = "new random text goes here"

your answer should follow that basic syntax with the correct information from the directions.

You did something similar here

the reason why you need to update the text is because when you click on the go to store button, text here should change from "Welcome to dragon repeller" to say instead "You enter the store."

here is a different example of how to work with innerText since there is some confusion on how this property works.

hope that helps

so i get the idea now, the question was a bit confusing.

i would basically use this

variableName.innerText = "You enter the store"```

but i update the variable name

yes, you would need to update the variable name from variableName to the one the directions want you to use.
but it looks like you are getting the general idea :+1:

the question doesn’t mention what the variable name should be replaced with

Here is the part of the directions you need to pay attention to for the variable name

Change the innerText property of the text

That is what Teller was mentioning here

hope that helps

1 Like

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