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

Tell us what’s happening:

step 124 (JavaScript)
monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;

this is my code and exacty matching all requirements still showing error why?

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="./styles.css">
    <title>RPG - Dragon Repeller</title>
  </head>
  <body>
    <div id="game">
      <div id="stats">
        <span class="stat">XP: <strong><span id="xpText">0</span></strong></span>
        <span class="stat">Health: <strong><span id="healthText">100</span></strong></span>
        <span class="stat">Gold: <strong><span id="goldText">50</span></strong></span>
      </div>
      <div id="controls">
        <button id="button1">Go to store</button>
        <button id="button2">Go to cave</button>
        <button id="button3">Fight dragon</button>
      </div>
      <div id="monsterStats">
        <span class="stat">Monster Name: <strong><span id="monsterName"></span></strong></span>
        <span class="stat">Health: <strong><span id="monsterHealth"></span></strong></span>
      </div>
      <div id="text">
        Welcome to Dragon Repeller. You must defeat the dragon that is preventing people from leaving the town. You are in the town square. Where do you want to go? Use the buttons above.
      </div>
    </div>
    <script src="./script.js"></script>
  </body>
</html>
/* file: styles.css */
body {
  background-color: #0a0a23;
}

#text {
  background-color: #0a0a23;
  color: #ffffff;
  padding: 10px;
}

#game {
  max-width: 500px;
  max-height: 400px;
  background-color: #ffffff;
  color: #ffffff;
  margin: 30px auto 0px;
  padding: 10px;
}

#controls,
#stats {
  border: 1px solid #0a0a23;
  padding: 5px;
  color: #0a0a23;
}

#monsterStats {
  display: none;
  border: 1px solid #0a0a23;
  padding: 5px;
  color: #ffffff;
  background-color: #c70d0d;
}

.stat {
  padding-right: 10px;
}

button {
  cursor: pointer;
  color: #0a0a23;
  background-color: #feac32;
  background-image: linear-gradient(#fecc4c, #ffac33);
  border: 3px solid #feac32;
}
/* file: script.js */

// User Editable Region



monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

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

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

I tried but it still shows like
// running tests 1. You should use the same

monsterHealth

line you already wrote. 2. You should add to the

weapons[currentWeaponIndex].power

value. 3. You should use

Math.floor()

. 4. You should use

Math.random()

. 5. You should multiply

Math.random()

by the value of

xp

. 6. You should use

Math.floor()

to round the result of

Math.random() * xp

down. 7. You should add

1

to the result of

Math.floor()

. 8. You should add the result of

Math.floor(Math.random() * xp) + 1

to the result of

weapons[currentWeaponIndex].power

. // tests completed // console output Uncaught ReferenceError: weapons is not defined [ReferenceError: attack is not defined] [ReferenceError: attack is not defined] [ReferenceError: attack is not defined] [ReferenceError: attack is not defined] [ReferenceError: attack is not defined] [ReferenceError: attack is not defined] [ReferenceError: attack is not defined] [ReferenceError: attack is not defined]

reset the step and try again, that error is not related to your code

I have done that too… but still i cant pass the test ..showing same error. i even close the chrome and do it again still shows the same

can you share all the code in your editor?

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

my entire code is not shown in the page
it visible on the screen till before one step
from this step the entire code is not visible on screen only the particular part is available on screen


you can’t be on line 1, reset the step, you have lost quite a lot of code

I have tried …I am still on line 1 …I have reset the code and checked .still same problem..

are you pressing here the Reset this lesson button?

after that what happens?

if you do not restore the step code you are not going to pass

I think My lap has some issue ..I try again sometime.

did you try these suggestions?

yeah… Now its working..
Thanks for your time and response