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.
Im here, and here´s my code:
function sellWeapon() {
if (inventory.length > 1) {
gold += 15;
goldText.innerText = gold;
let currentWeapon = inventory.shift();
text.innerText = "You sold a " + currentWeapon + "." ;
text.innerText = " In your inventory you have: " += inventory;
}
}
I looked other forum posts and copied their code but it doesnt work, and it doesn´t say why (It doesnt show the message with the error, only the button to reset the lesson).
Thank you for the help
Hello, a += b is like saying a = a + b, so basically the += operator is used to avoid repeating the same element on the right side of the assignment this means you can also do this a += b + c which is a = a + b + c
In you case you are asked to add " In your inventory you have: " & inventory to text.innerText, you should replace the += before the inventory variable & add += right after text.innerText instead of =
You need + only before inventory array, and you missing + for your assignment operator = . Also place your last quotation mark after your concatenate operator.