Home > Enterprise >  how to add and/or subtract numbers using html and js to make a buy and sell system?
how to add and/or subtract numbers using html and js to make a buy and sell system?

Time:04-28

I want to make a system when you click:

{before click = Coins: 0}

{after click = Coins: 1}

use js.

add(x);
remove(x);

and I want to make shops:

function e() {
var demo = document.getElementById('demo').innerHTML=add(1);
}

and

<button onclick="e()">get 1 coin</button>

to make this:

function e() {
  var demo = document.getElementById('demo').innerHTML = "Coins: 1";
}
<!DOCTYPE>
<html>

<body>
  <p id='demo'>Coins: 0</p>
  <button onclick="e()">get 1 coin(plz edit this code)</button>
</body>

</html>

CodePudding user response:

<html>
<body>
<p id='demo'>Coins: 0</p>
<!-- get web script form javascript -->
<script>
let counter =0;
function e() {
counter  ;
  var demo = document.getElementById('demo').innerHTML=`Coins: ${counter}`;
}
</script>
<button onclick="e()">get 1 coin(plz edit this code)</button>
</body>
</html>

CodePudding user response:

<html>
<body>
<p id='demo'>Coins: 0</p>
<!-- get web script form javascript -->
<script>
let counter =0;
function e() {
counter =5;
  var demo = document.getElementById('demo').innerHTML=`Coins: ${counter}`;
}
function b() {
counter-=5;
  var demo = document.getElementById('demo').innerHTML=`Coins: ${counter}`;
}
</script>
<button onclick="b()">remove 5 coin(plz edit this code)</button>
</body>
</html>

  • Related