Back to Freecodecamp

Step 19

curriculum/challenges/english/blocks/learn-basic-javascript-by-building-a-role-playing-game/62a23d1c5f1c93161f3582ae.md

latest3.8 KB
Original Source

--description--

Similar to your #stats element, your #monsterStats element needs two span elements. Give them the class stat and give the first element the text Monster Name: and the second the text Health: . After the text in each, add a strong element with an empty nested span element. Give the first inner span element an id of monsterName and the second inner span element an id of monsterHealth.

--hints--

Your #monsterStats element should have two span elements.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
assert.equal(spans.length, 2);

Your new span elements should both have a class value of stat.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
assert.equal(spans[0].className, 'stat');
assert.equal(spans[1].className, 'stat');

Your first span element should have a strong element with an empty nested span element.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
const strong = spans[0]?.querySelector('strong');
const span = strong?.querySelector('span');
assert.exists(strong);
assert.exists(span);

Your second span element should have a strong element with an empty nested span element.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
const strong = spans[1]?.querySelector('strong');
const span = strong?.querySelector('span');
assert.exists(strong);
assert.exists(span);

Your first span element should have the text Monster Name: . Make sure the spacing is correct.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
assert.match(spans[0].innerHTML, /Monster Name:\s+/);

Your second span element should have the text Health: . Make sure the spacing is correct.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
assert.match(spans[1].innerHTML, /Health:\s+/);

Your strong and span elements should come after the text.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
assert.match(spans[0].innerHTML, /Monster Name:\s+<strong>/);
assert.match(spans[1].innerHTML, /Health:\s+<strong>/);

Your first inner span element should have an id of monsterName.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
const span = spans[0]?.querySelector('span');
const spanId = span?.id;
assert.equal(spanId, 'monsterName');

Your second inner span element should have an id of monsterHealth.

js
const spans = document.querySelectorAll(`#monsterStats > span`);
const span = spans[1]?.querySelector('span');
const spanId = span?.id;
assert.equal(spanId, 'monsterHealth');

--seed--

--seed-contents--

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>
--fcc-editable-region--
      <div id="monsterStats">

      </div>
--fcc-editable-region--
      <div id="text"></div>
    </div>
    <script src="./script.js"></script>
  </body>
</html>
js
let xp = 0;
let health = 100;
let gold = 50;
let currentWeaponIndex = 0;
let fighting;
let monsterHealth;
let inventory = ["stick"];

const button1 = document.querySelector("#button1");
const button2 = document.querySelector("#button2");
const button3 = document.querySelector("#button3");