Step 35 (Declare a new variable with the `const` keyword and name it `monsterHealthText`.)

Step 35

Finally, use querySelector() to get the #monsterHealth element. Because you have already declared a monsterHealth variable earlier, you need to use a different variable name for this element.

Declare a new variable with the const keyword and name it monsterHealthText.

When i press ‘Check your code’, nothing happens, and if i open it in read-only, it says this: SyntaxError: unknown: Missing initializer in const declaration. (18:23) 16 | const monsterStats = document.querySelector(“#monsterStats”); 17 | const monsterName = document.querySelector(“#monsterName”); > 18 | const monsterHealthText | ^.

What am I doing wrong?

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;

I tried with ‘‘const monsterHealthText=document.querySelector(“#monsterHealth”);’’ and ‘‘const monsterHealthText=document.querySelector(“#monsterHealth”);’’ , and it still didn t work.

This is telling you that you have a syntax error in your code. When you declare a variable as a const then you have to assign it a value at the same time. So my guess is that you aren’t doing that, but can’t be sure without seeing your code.

If you can’t figure it out, please paste your code in here using the following method so that we can see it properly.

To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

1 Like

I edited the post, thanks for telling me.

1 Like

So ya, this you definitely can’t do. There needs to be an equals sign and a value.

This looks right to me. Please try again and if it doesn’t work then paste all of your JS in here. Also, it might help if you reset the step to get the original JS back just to make sure you didn’t accidentally change something you aren’t seeing.

1 Like

It worked after I tried some more. Thank you

2 Likes

Im having the same issue, ive tried the advice above with no joy. Ive reset the step a couple of times.

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 monsterHeathText = document.querySelector("#monsterHealthText");

FYI, the next time you have an issue, please start your own topic using the Help button in the step. But I will give you a hint here as I have a joke I want to use.

Look closely at your variable name. It sounds like you want to give the monster a popular candy bar, which probably isn’t very good for its health.

1 Like

Man, i looked at that so many times. Thanks.

It doesn’t matter how experienced of a developer you are, little typo errors in a page of code can have you putting your head through the wall all day. Keep it up! And I promise, this won’t be the last time you make that mistake! :rofl:

1 Like

Done it twice today already lol

The good news is that in proper code editors like VS Code (or even playcode.io website) will highlight your variables and hopefully help you see these mistakes easier.

1 Like