2

I am trying to make a clicker game, and I am dividing the wait time for a new click (the currency) for each clicker, but it is not working even though the variable is updating.

Here is my code

var clickers = 1;
var x = 0;

function fun() {
  x = x + 1;
  const element = document.getElementById("id01");
  element.innerHTML = x;

}
function myFunction() {
  var number = x;
  document.getElementById("myText").innerHTML = number;
}

//here is how we will buy auto clickers, and how they work

function buyClicker() {
  clickers += 1;
  alert(clickers)
  x -= 20;
  const element = document.getElementById("id01");
  element.innerHTML = x;
}

window.setInterval(function() {
  x = x + 1;
  const element = document.getElementById("id01");
  element.innerHTML = x;
}, 1000 * clickers);
<!DOCTYPE html>
<html>

<head>
  <body onload="myFunction()">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>replit</title>
  <link href="style.css" rel="stylesheet" type="text/css" />
  <script src="script.js"></script>
</head>

<body>
  <h1 id="id01"> The value for number is:  <span id="myText"></span></h1>
  <h1>HERE IS OUR GAME :D</h1>

<button id="demo" onclick="fun()">make clicks</button>
<button id="demo" onclick="buyClicker()"> buy clicker</button>

I was trying to add to this variable over time, wait time decreasing each time, but it will not decrease

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • not gonna solve the issue but, ids are unique and you have 2 elements with the same id in your HTML `` and `` – Chris G May 11 '23 at 18:20
  • for me `x` decreases correctly after you close the alert – mimak May 11 '23 at 18:21

0 Answers0