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";
}
ILM
March 1, 2024, 11:52am
2
what issue are you having? we need more context
Teller
March 1, 2024, 11:54am
3
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.
ILM
March 1, 2024, 12:01pm
5
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
up695407:
"You enter the store"
You need a dot .
after “store” text in the text.innerText .
Teller
March 2, 2024, 1:55am
8
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:
On a separate line type three back ticks.
On a separate line paste your code.
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
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
Teller:
The variable is text
hope that helps
1 Like
system
Closed
September 3, 2024, 3:59am
16
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.