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

Tell us what’s happening:

Task is to add " In your inventory you have: " to the end of text.innerText.What is wrong?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
    currentWeaponIndex++;
    goldText.innerText = gold;
    let newWeapon = weapons[currentWeaponIndex].name;
    text.innerText+= " In your inventory you have:  " = " You now have a " + newWeapon + "."; 
    inventory.push(newWeapon);
    
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0

Challenge Information:

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

Hi there! Don’t change the given code, add new line of code by assigning this string to text.innerText

Still not working:

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
    currentWeaponIndex++;
    goldText.innerText = gold;
    let newWeapon = weapons[currentWeaponIndex].name;
    text.innerText = " You now have a " + newWeapon + ".";
    text.innerText+= " In your inventory you have:  "+inventory.join(", ")+".";
    inventory.push(newWeapon);
    
  }
}

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 (').

I don’t think you should have two consecutive spaces

1 Like

Yes, that’s the issue