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

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.onclick="goStore()";
}

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

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

Am i missing something here?

What error message are you getting? Looking carefully at the exact wording of the error message can often help.

after applying same code as above just edit function gostore() with console.log(“Going to Store”) it works perfectly

i don’t get an error message

like this?

console.log(“Going to Store”) {
button1.onclick="goStore()";
}```

What do the instructions say?

I have updated to this

console.log(“Going to Store”) {
button1.onclick="Buy 10 health (10 gold)";
}```

so i need to update the first line as well i’m guessing?

I don’t want to tell you the answer - I want to help you work it out yourself. Let’s start by telling me what the instructions for this step say

Remove the code inside the goStore function and add a line that updates the text of button1 to say Buy 10 health (10 gold)

Ok. Notice that the instructions are to update the text of button1, so how would you do that?

i have updated the button1.
do i also have to update the console log?

Let’s have a look at your code first

console.log(“Buy 10 health (10 gold)”) {
button1.onclick="Buy 10 health (10 gold)";
}```

You have updated button1’s onclick property, not its text.

When I asked you what the instructions said, you only gave me the botton part of the instructions. What does the top part say?

to change the text.

this is the full question
The innerText property controls the text that appears in an HTML element. For example:

const info = document.querySelector("#info");
info.innerText = "Hello World";

This code would change the element assigned to the info variable to have the text Hello World.

When a player clicks your Go to store button, you want to change the buttons and text. Remove the code inside the goStore function and add a line that updates the text of button1 to say Buy 10 health (10 gold).

Right, so the instructions are showing you how to change an element called info.
How do you think you could change your element called button1?

is it this?

const info = document.querySelector("#goStore");

No.
You’ve already got your element here:

So, now, look at the instructions:

Notice this changes the element called info to have text Hello World.
What property of info was used here?