const inputEl = document.querySelector('input')
const btnMinus = document.querySelector('.btn-minus')
const btnPlus = document.querySelector('.btn-plus')
const changeInputValue = num => {
const newValue = inputEl.value + num
inputEl.value = newValue
inputEl.setAttribute('value', newValue)
}
btnMinus.addEventListener('click', () => {
changeInputValue(-1)
})
btnPlus.addEventListener('click', () => {
changeInputValue(1)
})
const priceEl = document.querySelector('.price')
const resultEl = document.querySelector('.result');
const callback = mutationList => {
for (const mutation of mutationsList) {
if (mutation.attributeName === 'value') {
resultEl.textContent = priceEl.textContent * inputEl.value
}
}
};
const observer = new MutationObserver(callback);
observer.observe(inputEl, { attributes: true });