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

Tell us what’s happening:

Im Struggling in Step 91

Your code so far

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.

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

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

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/15.6 Safari/605.1.15

Challenge Information:

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

You already have a variable that points to the name of the new weapon, this variable newWeapon, so, you do not need to redeclare another variable, this one

All you have to do now is concatenate your string with the newWeapon variable. Instead of using the variable you declared here (ourName), use the one that was initially declared.

1 Like

Hey thanks for the hep but I still can’t seem to get it. This is my code so far,

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

never mind solved it!

1 Like

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

1 Like

I still can’t seem to get it?

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.