From 20ce5a330f624b058797aae24c07c3034abd142b Mon Sep 17 00:00:00 2001 From: Wender Azevedo Date: Wed, 9 Nov 2022 22:25:11 -0300 Subject: [PATCH] =?UTF-8?q?Adiciona=20fun=C3=A7=C3=A3o=20as=20bot=C3=B5es?= =?UTF-8?q?=20de=20+=20e=20-.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 25 +++++++++++++++++++++++++ index.html | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 app.js 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