diff --git a/app.js b/app.js new file mode 100644 index 0000000..02ff6a5 --- /dev/null +++ b/app.js @@ -0,0 +1,25 @@ +document.addEventListener("DOMContentLoaded", function() { + const quantityInput = document.querySelector(".shopping-form-quantity-input"); + const incrementButton = document.querySelector(".shopping-form-increment-button"); + const decrementButton = document.querySelector(".shopping-form-decrement-button"); + + incrementButton.addEventListener("click", incrementQuantity); + decrementButton.addEventListener("click", decrementQuantity); + + function incrementQuantity() { + const currentValue = Number(quantityInput.value); + const newValue = currentValue + 1; + + quantityInput.value = newValue; + } + + function decrementQuantity() { + const currentValue = Number(quantityInput.value); + const newValue = currentValue - 1; + + if (newValue > 0) { + quantityInput.value = newValue; + } + + } +}); \ No newline at end of file diff --git a/index.html b/index.html index af7b6a0..272aa70 100644 --- a/index.html +++ b/index.html @@ -38,5 +38,7 @@ + + \ No newline at end of file