Step 108:
Use an else statement to run when the inventory length is not more than one. Set the text.innerText to say Don't sell your only weapon! .
Have done everything bu it still shows an error:
SyntaxError: unknown: Missing semicolon. (115:30) 113 | text.innerText = "You sold a " + currentWeapon + “.”; 114 | text.innerText += " In your inventory you have: " + inventory} > 115 | else (inventory.length
### Your code so far
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}
else (inventory.length <= 1) {
text.innerText = “Don’t sell your only weapon!”;
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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 108
Maybe there’s a bug? Here’s the working code that I initially provided as an answer, but it wasn’t accepted. Then I came across this thread when I actually Googled the actual step and its instructions. I tried the “else if” advice even though it felt redundant. I attempted four possible “else if” options until I encountered a syntax error message about an extra curly bracket on line 104, which I didn’t even modify. I removed it, and finally, it worked.
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.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
Oh, thank you so much. My bad. Are you referring to the “Ask for Help” feature that pops up when I kept providing the wrong answer? I think it was mentioned here.
Which was actually confirmed by:
So, I don’t know. As far as I know, the lesson doesn’t make you write a code that wasn’t discussed yet. And I don’t think Lesson 108 discussed “else if,” but only “if else.”