Hey everyone, kindly walk me through this, my code and instruction are below;
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 = location["Sell weapon for 15 gold"][1];
button2.onclick = location["sellWeapon"][1];
}
The instruction is below;
Once a player has the most powerful weapon, you can give them the ability to sell their old weapons.
In the outer else
statement, set button2.innerText
to Sell weapon for 15 gold
. Also set button2.onclick
to the function name sellWeapon
.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15
Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 100