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

hello

can anyone help with this step please? I had to delete the code I wrote (which was not accepted) as otherwise I could not post to the help forum.

I basically wrote the following:

text.innerText = "You now have a " + newWeapon + " . " += "In your inventory you have: ";

### Your code so far

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

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

2 Likes

Two issues

  1. check your spaces. You don’t usually put a space before a . period is a sentence

  2. you can only use += with a variable on the left

thank you.

Sorry, not sure though as there is no space between newWeapon and “.”? (or is there?)

Also, the instruction tells you:

" This time, use the += operator to add text to the end of text.innerText` " (No mention of variables?)

You wrote an extra space here before the period

The thing immediately to the left of the+= isn’t the variable you were told to append to

text.innerText = "You now have a "+ newWeapon + "." += "In your inventory you have: ";

thank you. I have omitted that space and have the code above, which doesn’t work either. Any idea what I’m doing wrong?

you have two assignments on the same line. You can’t add += at the end of a line

Did you see my last reply?

ok. I think I am confused by the way the q. is asked.

Does this mean that I need a new line starting with text.innerText += ?

Yes. You cannot assign (use =) to something that isn’t a variable

1 Like

great, got it. thank you.

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

  }
}

I don’t understood!

hey @MaryGothic

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.