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

Tell us what’s happening:

Hello, per the instructions I have moved the script element out of the head and into the last line of the body (code below). For this forum post, I have added a comment in the head to show where the script element was, but I do not have this in my actual lesson when I try to run it. The script (opening and closing elements) are now immediately before the closing body element, but it will not accept this. Am I missing something? Thank you!

Your code so far

RPG - Dragon Repeller
XP: 0 Health: 100 Gold: 50
Go to store Go to cave Fight dragon
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">

<!-- User Editable Region -->

  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="./styles.css">
    <title>RPG - Dragon Repeller</title>
    <!-- Script element from line 24 was here -->
  </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"></div>
      <div id="text"></div>
    </div>
      <script src="./script.js"></script>  
  </body>

<!-- User Editable Region -->

</html>
/* file: script.js */
let xp = 0;
let health = 100;
let gold = 50;
let currentWeapon = 0;
let fighting;
let monsterHealth;
let inventory = ["stick"];

let button1 = document.querySelector("#button1");

Your browser information:

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

Challenge Information:

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

Welcome to the forum @darrin

Please do not add code not asked for in the instructions, otherwise the tests may fail.

Happy coding

Hello Teller,

There is nothing extra in my code not asked for in the instructions. Thank you

Your code passes, however I saw the comment you made and thought it was interfering with the tests.

Reset the step and try again. If that doesn’t work, refresh the page, disable dark mode, disable ad blockers. Or, use another browser.
If the above steps do not work, you may need to restart the computer.

Happy coding

Hi,

I retried again using the same code (copied and pasted actually) and it is now accepting it. Maybe a bug or cache issue before. Thank you!

1 Like