Witam mam problem. Otóż chciałem stworzyć 'grę' na wzór cookie clickera jednak nie umiem rozwikłać pewnej sprawy. Jak zrobić aby po kliknięciu guzika 'shop' następne kliknięcia były zwiększone np. o 3?. Liczę na pomoc i z góry dziękuję
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel = 'stylesheet' href = 'style.css'>
<script src = 'main.js' defer></script>
</head>
<body>
<button id = 'btn'>click</button>
<div id = 'result'></div>
<button id = 'shop'>Shop</button>
</body>
</html>
JS:
let button = document.getElementById('btn');
let result = document.getElementById('result');
let shopping = document.getElementById('shop');
let x = 0;
button.addEventListener('click',click);
shopping.addEventListener('click',shop);
function click(){
result.value = x;
x += 1;
result.innerHTML = x;
}
function shop(){
if(x >= 10){
x = x - 10;
}
else{
alert('Not enough points!');
}
result.innerHTML = x;
}