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