JSFiddle - React, Tailwind, and code Playground
by eget teteete
HTML
<div class="buy">
<button data-price='1000'>1000</button>
<button data-price='1000'>5000</button>
<button data-price='1000'>6000</button>
<button id='remove'>Удалить</button>
</div>
<p></p>
<p></p>
JavaScript
var arr = [];
var div = document.getElementsByTagName('div');
var p = document.getElementsByTagName('p')[0];
var p1 = document.getElementsByTagName('p')[1];
var btn = document.getElementsByTagName('button')[0];
var remove = document.getElementById('remove');
console.log(remove);
var price = btn.getAttribute('data-price');
var total = 0;
var tovar = 0;
btn.addEventListener('click', function() {
arr.push(price);
total += parseInt(arr);
p.textContent = total;
tovar++;
p1.textContent = tovar;
});
remove.addEventListener('click', function() {
arr.pop(price);
total -= parseInt(arr);
p.textContent = total;
tovar--;
p1.textContent = tovar;
if (total != number) {
total = 0;
}
if (tovar <= 0) {
tovar = 0;
}
});