Help :(

Joined
Aug 17, 2021
Messages
2
Reaction score
0
I'm working on simple clicker game to improve my coding skills, and ran into this error. I cant fix it because I'm an idiot. Here's my code

Code:
<HTML>
  <HEAD>
      <title>Lemon Clicker</title>
    </head>
    <body>
      <p>Lemons: <span id="score">0</span></p>
      <img src="images/lemon.png" hight="512px" width="512px" onClick="addToScore(1)">

      <button onclick="buyCursour">Cursor <span id="cursorcost">15</span> -- <span id="cursors">0</span></button>
    <script>
      var score = 0;

      var cursorCost = 20;
      var cursours = 0;

      function buyCursour() {
        if (score >= cursorCost) {
          score = score - cursorCost;
          cursours = cursours + 1;
          cursorCost = Math.round(cursorCost * 1.15);
          document.getElementById("score").innerHTML = score;
          document.getElementById("cursorCost").innerHTML = cursorCost;
          document.getElementById("cursors").innerHTML = cursors;
        }
      }

      function addToScore(amount) {
        score = score + amount;
        document.getElementById("score").innerHTML = score;
      }
    </script>
    </body>
</HTML>
 
Last edited:
Joined
Aug 17, 2021
Messages
2
Reaction score
0
Sorry I didn't state what the error was. When you buy a new cursor, It doesn't increase your cursor count and doesn't subtract lemons.
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
'
<button onclick="buyCursour">' does not call your JS fuction. SB (should be) <button onclick="buyCursour()"> with parentheses.
 
Last edited:
Joined
Aug 18, 2021
Messages
3
Reaction score
1
I'm working on simple clicker game to improve my coding skills, and ran into this error. I cant fix it because I'm an idiot. Here's my code

Code:
<HTML>
  <HEAD>
      <title>Lemon Clicker</title>
    </head>
    <body>
      <p>Lemons: <span id="score">0</span></p>
      <img src="images/lemon.png" hight="512px" width="512px" onClick="addToScore(1)">

      <button onclick="buyCursour">Cursor <span id="cursorcost">15</span> -- <span id="cursors">0</span></button>
    <script>
      var score = 0;

      var cursorCost = 20;
      var cursours = 0;

      function buyCursour() {
        if (score >= cursorCost) {
          score = score - cursorCost;
          cursours = cursours + 1;
          cursorCost = Math.round(cursorCost * 1.15);
          document.getElementById("score").innerHTML = score;
          document.getElementById("cursorCost").innerHTML = cursorCost;
          document.getElementById("cursors").innerHTML = cursors;
        }
      }

      function addToScore(amount) {
        score = score + amount;
        document.getElementById("score").innerHTML = score;
      }
    </script>
    </body>
</HTML>
since your question has already been answered, I would like to give you some advice, and it is not stupid, use local let variables instead of global var

e.g

JavaScript:
let abc = "Hello";
alert(abc)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top