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

Tell us what’s happening:

hey everyone, kindly walk me through this, the instruction is below;

On a new line, add the string You attack it with your <weapon>. to the text value, replacing <weapon> with the player’s current weapon. Additionally, remember that this line of text starts with a space so it will properly display.

the code is below;

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText = "You attack it with your " + monsters[fighting].name + " .";

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15

Challenge Information:

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

As it says, you need to add the string, not ‘replace’ it

appreciate your reply. How about the instruction " …replacing <weapon> with the player’s current weapon. Additionally, remember that this line of text starts with a space so it will properly display."

It looks like you are trying to get the current monster’s name here

but the directions say to get the current weapon name

Remember that weapons is an array

const weapons = [
  { name: 'stick', power: 5 },
  { name: 'dagger', power: 30 },
  { name: 'claw hammer', power: 50 },
  { name: 'sword', power: 100 }
];

Also, remember that the currentWeapon variable represents the current index for the players current weapon.

With that information, how would you access the player’s current weapon?

If you need help with syntax, then look to what you wrote here

it follows that same pattern but you need to reference the correct variable names

I’m the pitch here is explained as a fight of some sort, between monsters in a fantasy land, who is your explanation. weapon is “knife” please, and involved action of pulling a knife.

Thanks for your reply. I attempted this;

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText = "You attack it with your " + dagger + " .";
}

You don’t want to hardcode dagger here.

You want to follow this syntax here

Your answer should look like that.
But instead of getting the monster’s current name, you need to get the weapon’s current name

How would you get the current weapon?

As as sidenote, you don’t need this extra space here

I could come up with this;

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText = "You attack it with your " + weapons[currentWeapon].name + ".";
}

It is getting closer.

You still have two small issues to resolve.

The first has to deal with the initial comment you received here

You are still using the assignment operator here

but the directions say to use the coumpound assignmnet operator.
You will need to fix that

Once you fix that, then you need to fix the spacing issue here

Remember that you are adding a sentence to the end of the previous sentence.

So, you need to have a space at the beginning of that string to fix the spacing issue

Once I fix those things, with your code, then it passes

I’m more confused tbh. gotta take a rest cause my head is aching already. Thanks for reply.

taking breaks is good :+1:

Hey Jessi, firstly, how do I use a compound assignment operator? my code Is below;

function attack() {
  text.innerText = "The " + monsters[fighting].name + " attacks.";
  text.innerText = "You attack it with your " + weapons[currentWeapon].name + ".";
}

Scroll back up to line 133 in your code - you have an example there where you used it

1 Like

Appreciate Jessi and Jeremy. Completed!!!

2 Likes