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

Tell us what’s happening:

Your if statement should check if gold is greater than or equal to 10

How do I have it so then my ‘if’ statement checks if ‘gold’ is greater than or equal to ‘10’??

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36

Challenge Information:

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

My code so far

function buyHealth() {
  if (num >= 10) {
  gold -= 10;
  health += 10;
  goldText.innerText = gold;
  healthText.innerText = health;
  console.log("This code will run because num is greater than or equal to 10.")
  }
}

Please post the code you’ve tried so far. Thanks

I don’t think you have a num variable in your code. Are you sure that is the value to check?

function buyHealth() {
if (num >= 10) {
gold -= 10;
health += 10;
goldText.innerText = gold;
healthText.innerText = health;
console.log(“This code will run because num is greater than or equal to 10.”)
}
}

I do, see?

Hi @lehcar652

The instructions ask you to compare a certain variable . Your code is comparing the variable given in the example.

Also remove the console.log as it will inter with the tests.

Happy coding

I mean there is no num variable created before this snippet, you can check only a variable that has already a value, num doesn’t

If you console.log(num) inside of that buyHealth() function, you will probably get undefined because of what Ilenia is illuding to. Is there another variable name you should be checking if its greater or less than 10?

So what you saying is to put my console.log out of my buyHealth() function?

No, but if you did you will likely log undefined.

The solution is to change num to some other variable that is referencing the amount of currency the player has

Ohh okay… That makes a little bit sense but what should I do??

Well like @ILM said. There isn’t a num variable. You essentially have a typo.

What is the currency in this game we are building?

Your if statement should check if gold is greater than or equal to 10

How exactly do I do that?

change this if (num >= 10)
to if (gold >= 10)

Ohh okay I will give that a try

It is great that you solved the challenge, but instead of posting your working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

It now says " All of your buyHealth code should be inside the if statement"

Jeremy can you suggest an alternative way of helping him get to this answer? We all took the steps to help this person get here. And we blocked the answer using Spoilers and even did not directly expose the entire solution to the forum. Instead we took steps to gently guide the user to the solution.

Please suggest how we could have improved this?

Do not post solution code.