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

Sorry, your code does not pass. Keep trying.

All of your buyHealth code should be inside the if statement. assist kindly

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 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(gold) {

    gold -= 10;
    health += 10; 
    console.log("Health potion purchased! Health +10");
    console.log("Remaining gold: " + gold);
    console.log("Current health: " + health);
}

function buyWeapon() {

}

function fightSlime() {

}

function fightBeast() {

}

Hi.
Provide your code please.

You must create an if statement and set its condition per the instructions. This link will help if you’re unfamiliar with the statement.

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