Adiciona função as botões de + e -.

This commit is contained in:
Wender Azevedo 2022-11-09 22:25:11 -03:00
parent 1ff2f009c8
commit 20ce5a330f
2 changed files with 27 additions and 0 deletions

25
app.js Normal file
View File

@ -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;
}
}
});

View File

@ -38,5 +38,7 @@
</form> </form>
</section> </section>
</main> </main>
<script src="app.js"></script>
</body> </body>
</html> </html>