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

Tell us what’s happening:

Hello everyone, kindly walk me through this challenge.

Your code so far

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
    currentWeapon++;
    goldText.innerText = gold;
    let newWeapon = weapons[currentWeapon].name;
    text.innerText = "You now have a"
  }
}

The instruction is "You can insert variables into a string with the concatenation operator +. Update the You now have a new weapon. string to say You now have a and the name of the new weapon. Remember to end the sentence with a period.

Here is an example that creates the string Hello, our name is freeCodeCamp.:

const ourName = "freeCodeCamp";
const ourStr = "Hello, our name is " + ourName + "."

How do I update the text.innerText with the string?


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 91

This is not finished. Use the following rule for concatenating a string and a variable (in this challenge):

... = "Text " + variable + ".";

Read the instructions again.

Appreciate your help. I came up with this but still wrong for some reason.

function buyWeapon() {
  if (gold >= 30) {
    gold -= 30;
    currentWeapon++;
    goldText.innerText = gold;
    let newWeapon = weapons[currentWeapon].name;
    text.innerText = "You now have a" + variable + ".";
  }
}

Your variable has a name. Take a look at one line above this in question. The ‘variable’ is put in the post just as guidance. The real name of the variable is the name that follows the let. Also, make sure you add one blank space after the letter ‘a’ in the text You now have a.

1 Like

Got it!! Appreciate.

1 Like

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