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

Stuck on step 34, hoping someone can help me out here.

Getting error:
SyntaxError: unknown: Identifier ‘text’ has already been declared. (20:6) 18 | let monsterName; 19 | > 20 | const text = document.querySelector(“#text”); | ^ 21 | const xpText = document.querySelector(“#xpText”); 22 | const healthText = document.querySelector(“#healthText”); 23 | const goldText = document.querySelector(“#goldText”);

Here is my code so far:

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");

let text;

let xpText;

let healthText;

let goldText;

let monsterStats;

let monsterName;

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");

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

This is telling you that you are declaring the variable text twice, which you can’t do in JS. It looks like you declared every variable with let first and then declared them again with const when you assigned their value. Based on the error message above, what do you think you need to do to fix this?

I understand now. Since I’m already declaring them as constants on the line with my query I shouldn’t need to declare them beforehand, so I removed all the let statements, and passed! Thanks for pointing me in the right direction.

1 Like