Learn basic javascript by building a role play game step 43

Hi Guys im new to this and seem to be really struggling i cant see what i have done wrong can you help please thanks steve

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)”;
}

function goCave() {
button2.innerText = “Buy weapon (30 gold”;
}

function fightDragon() {
button3.innerText = “Go to town square”;
}

Hello:)
What is your question?

All of your code should be in the goStore function.

Hi i keep on getting a error on step 43 about button2 and i cant see what i have done wrong

Step 43:

Now, add a line that updates the text of button2 to say Buy weapon (30 gold) and update the text of button3 to say Go to town square.

You need to keep adding to your function such as:

function goStore() {
  button1.innerText = "Buy 10 health (10 gold)";
  button2.innerText = "Buy weapon (30 gold)";
  ...
}
1 Like

In the cave you cannot buy anything or while you are fighting with the dragon.

great thanks on button3 button3.innerText = “Go to town square”;
would that go into the fight dragon function

No, that should go into the goStore() function as well.

The goStore() function needs to change the value of all the buttons to reflect something of a store, when you click on the store button. The cave, and fight dragon come later.

There is really only one more line of code that you need to add to that function. Please let me know if you’re still stuck.

Hi Thanks for the help im still getting the error is this correct
function goStore() {
button1.innerText = “Buy 10 health (10 gold)”;
button2.innerText = “Buy weapon (30 gold”;
button3.innText = “Go to town square”;
}
but i get this error
You should update the innerText property of button2 to be Buy weapon (30 gold).

button3.innText should equal button3.innerText .
And look at your string values to make sure they exactly match what is expected.

That should solve your problem. :slight_smile:

In every step you have to change the code right away under the explanation of the task and above the submit button. Nowhere else.

Should be:

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

ah im sorry to hassle you yea i potted int innerText error but still get the same error
function goStore() {
button1.innerText = “Buy 10 health (10 gold)”;
button2.innerText = “Buy weapon (30 gold”;
button3.innerText = “Go to town square”;
}

Look at the button2 string. It needs a closing ‘)’ as in Buy weapon (30 gold)

1 Like

Thats done it cheers for your help ive been trying to figure it out for 2 days im finding javascript tough thanks again for your patience and hlep Steve

2 Likes

No problem! Javascript can be a bit of a challenge at first. I hope you keep at it, and good luck!

ah… I get it now. we clicked Go to store… now the buttons change, because we’re now IN the store. that was not making sense about why they were changing or what they were doing.

2 Likes

Thanks a lot @paradoxi

1 Like