Submit button not working?

I am currently working through the Javascript curriculum, and Ive noticed that sometimes after typing my code and hitting submit nothing happens? It wont even tell me I have something right or wrong, it doesnt even seem to register that Ive clicked the submit button. Ive tried disabling popups, using a different browser and nothing worked, usually I just come back later and hope its working. Is this a known issue? Any help would be appreciated!

Hi @tallgirlsfinishlast

Next time this happens please post your full code so the forum can assist.

Use the following method to post code to the forum:

  1. On a separate line type three back ticks.
  2. On a separate line paste your code.
  3. On the last line type three back ticks. Here is a single back tick `

Happy coding

This is Step 102 of the first Javascript module:

‘’’
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”);
const weapons = [
{ name: ‘stick’, power: 5 },
{ name: ‘dagger’, power: 30 },
{ name: ‘claw hammer’, power: 50 },
{ name: ‘sword’, power: 100 }
];
const locations = [
{
name: “town square”,
“button text”: [“Go to store”, “Go to cave”, “Fight dragon”],
“button functions”: [goStore, goCave, fightDragon],
text: “You are in the town square. You see a sign that says "Store".”
},
{
name: “store”,
“button text”: [“Buy 10 health (10 gold)”, “Buy weapon (30 gold)”, “Go to town square”],
“button functions”: [buyHealth, buyWeapon, goTown],
text: “You enter the store.”
},
{
name: “cave”,
“button text”: [“Fight slime”, “Fight fanged beast”, “Go to town square”],
“button functions”: [fightSlime, fightBeast, goTown],
text: “You enter the cave. You see some monsters.”
}
];

// initialize buttons
button1.onclick = goStore;
button2.onclick = goCave;
button3.onclick = fightDragon;

function update(location) {
button1.innerText = location[“button text”][0];
button2.innerText = location[“button text”][1];
button3.innerText = location[“button text”][2];
button1.onclick = location[“button functions”][0];
button2.onclick = location[“button functions”][1];
button3.onclick = location[“button functions”][2];
text.innerText = location.text;
}

function goTown() {
update(locations[0]);
}

function goStore() {
update(locations[1]);
}

function goCave() {
update(locations[2]);
}

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

function buyHealth() {
if (gold >= 10) {
gold -= 10;
health += 10;
goldText.innerText = gold;
healthText.innerText = health;
} else {
text.innerText = “You do not have enough gold to buy health.”;
}
}

function buyWeapon() {
if (currentWeapon < weapons.length - 1) {
if (gold >= 30) {
gold -= 30;
currentWeapon++;
goldText.innerText = gold;
let newWeapon = weapons[currentWeapon].name;
text.innerText = "You now have a " + newWeapon + “.”;
inventory.push(newWeapon);
text.innerText += " In your inventory you have: " + inventory;
} else {
text.innerText = “You do not have enough gold to buy a weapon.”;
}
} else {
text.innerText = “You already have the most powerful weapon!”;
button2.innerText = “Sell weapon for 15 gold”;
button2.onclick = sellWeapon;
}
}

function sellWeapon() {
if (inventory.length > 1) {
gold += 15;
goldText.innerText = gold;
let currentWeapon =
}
}

function fightSlime() {

}

function fightBeast() {

}
‘’’

Hi @tallgirlsfinishlast

This is a syntax error.

You don’t need the equals sign as the instruction ask you to just declare a variable, not assign anything at the moment.

Check the console for any messages.

SyntaxError: unknown: Unexpected token (66:0)
64 | goldText.innerText = gold;
65 | let currentWeapon =
> 66 | }
| ^

If there is a coding error sometimes there are no messages displayed when the submit button is clicked.

Also, when posting code use back ticks ` not quote marks, as this correctly formats posts.

Happy coding

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.