Question: " Now use the += operator to add the string " In your inventory you have: " and the contents of inventory to the text.innerText. Make sure to include the space at the beginning and end of the " In your inventory you have: " string."
My code:
function sellWeapon() {
if (inventory.length > 1) {
gold += 15;
goldText.innerText = gold;
let currentWeapon = inventory.shift();
text.innerText = "You sold a " + currentWeapon + "." + " In your inventory you have: " += inventory;
}
}
Ive tried the += operator both where I posted above and after the last string before I call to my inventory and neither really worked any insight is super appreciated!
Hmmm so I tried that and still nothing This is what I put in:
let currentWeapon = inventory.shift();
text.innerText = "You sold a " + currentWeapon + "." ;
text.innerText = " In your inventory you have: " += inventory;
I tried placing the += both at the beginning of the second innerText line (removing the ; from the first line) and then also where you see it above… am I missing something?
I suggest we correct this code, that you had earlier posted.
Now make the following changes:
The addition assignment operator should come after this text.innerText. You are assigning the string and the inventory variable to the text, so it should come first.
Then, in the place where you used an additional assignment operator, use a concatenation operator instead, which is simply the plus sign. This will add the value of your inventory variable to your string.
Make sure not to change the string in any way, do not delete or add anything, including spaces.
Im so sorry but Im still super lost hahah… so the addition operator should come after the FIRST innerText or the second? The way Im taking this is as follows:
let currentWeapon = inventory.shift();
text.innerText = "You sold a " + currentWeapon + "." + " In your inventory you have: " + inventory;
Which Ive already tried so there must be something Im not picking up on with your explanation. Is the second innerText needed still? Since it sounds to me as everything should be placed on the first innerText.
This should be applied to the second one. You have simply interchanged the operators. To make it easier, interchange the operators. Remember we are using the code below.