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

Tell us what’s happening:

Describe your issue in detail here.
it is not an issue but hang of system as I am defining all the things very easily but still hanged on the code
I gave it
function goStore(){button1.onclick=;} , I have left the space for more code after onclick property but still no improvements

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 */
let xp = 0;
let health = 100;
let gold = 50;
let currentWeapon = 0;
let fighting;
let monsterHealth;
let inventory = ["stick"];

const button1 = document.querySelector('#button1');
const button2 = document.querySelector("#button2");
const button3 = document.querySelector("#button3");
const text = document.querySelector("#text");
const xpText = document.querySelector("#xpText");
const healthText = document.querySelector("#healthText");
const goldText = document.querySelector("#goldText");
const monsterStats = document.querySelector("#monsterStats");
const monsterName = document.querySelector("#monsterName");
const monsterHealthText = document.querySelector("#monsterHealth");


/* User Editable Region */

// initialize buttons
function goStore() {
button1.onclick  ;
}

/* 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/120.0.0.0 Safari/537.36

Challenge Information:

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

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

You’re supposed to set this button equal to something, right?

I think you don’t know about the solution and telling me something else, I know the Answere but what to do with the system’s alert

I know what the solution to the Step is. I’m not sure what you are asking for exactly

Use dot notation to set the onclick property of your button1 to the function reference of goStore. This function will be something you write later. Note that button1 is already declared, so you don’t need to use let or const.

Your code doesn’t do this

I am asking the solution. can you help me?

do not define goStore now, you just need to set the onclick property of the function here

1 Like

I’m trying to. But I cannot write the answer for you.

You’re going to need to use an = to set this button

I did it also as
function goStore(){button1.onclick = ;}
I left the space after = sign because further I have to follow the instructions of the system but still system is giving the same message.

I was following this step brother

Step 37

button1 represents your first button element. These elements have a special property called onclick, which you can use to determine what happens when someone clicks that button.

You can access properties in JavaScript a couple of different ways. The first is with dot notation. Accessing the onclick property of a button would look like:

button.onclick

Use dot notation to set the onclick property of your button1 to the function reference of goStore. This function will be something you write later. Note that button1 is already declared, so you don’t need to use let or const.

The step doesn’t want you to use the ‘function’ keyword.

Also, you have to put something after an =, you can’t put an empty space there.

Yes, I read the step and quoted the part the tests are looking for to you brother

I did so but same there although nothing was required for the button1.onclick but I also tried to mention something but all in vain. I am working on it since last two hours but still no improvement. I am well aware of javascript and its functions
Sorry, your code does not pass. Hang in there.

You should assign the goStore function reference to button1.onclick.

Did you fix the two things I mentioned?

In the last code you showed, you wrote ‘function’ but you must not do this

Your last code had nothing but an empty space after the = but that is invalid JS. You have to put the name of the thing you want to set the button equal to.

Don’t define any function. That comes later. You should write a single line that only sets

this button equal to the name of the function you will create later.

Thanks a lot brother. Actually I was unable to understand what does it mean by the system. I have solved it with your help

1 Like

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