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

Tell us what’s happening:

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

else doesn’t take a condition, it handles all other cases

else if would take a new condition

1 Like

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.

## SyntaxError: unknown: Unexpected token (105:0) 103 | button2.onclick = sellWeapon; 104 | } > 105 | } | ^ 106 | 107 | function sellWeapon() { 108 | if (inventory.length > 1)

What I tried

else if (inventory.length < 1)
else if (inventory.length <= 1)
else if (inventory.length === 1 )
else if (inventory.length === 0)
Working code:
REMOVED
1 Like

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.

2 Likes

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.

2 Likes

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.”

1 Like

It just asks you to use an else statment, not else if

Yeah, I’m sorry 'cause I really thought adding an “else if” was the solution since it was in your reply to the OP with the label “Solution.”

And also the working code(now deleted); the original code I submitted didn’t pass.

It’s also step 108, which is what this thread is about. And I think I’m having the same issues as the OP, but with a different syntax error.

I don’t remember touching line 104, which is what the syntax error is talking about. Step 108 was somewhere around line 121, if I remember correctly.

This is exactly why you should open a new topic

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.