Commit 0164a24e authored by jonathan Courat's avatar jonathan Courat

block the quantity to 1 minimum #3

parent 5836b351
...@@ -45,7 +45,8 @@ let plusBt = document.querySelectorAll('.plusBt'); ...@@ -45,7 +45,8 @@ let plusBt = document.querySelectorAll('.plusBt');
function incrementQuantity() { function incrementQuantity() {
console.log(this); console.log(this);
this.previousElementSibling.innerHTML = Number(this.previousElementSibling.innerHTML) + 1; let qtyValue = Number(this.previousElementSibling.innerHTML);
this.previousElementSibling.innerHTML = qtyValue + 1;
} }
addEventListenerList(plusBt, 'click', incrementQuantity); addEventListenerList(plusBt, 'click', incrementQuantity);
...@@ -56,7 +57,11 @@ let minusBt = document.querySelectorAll('.minusBt'); ...@@ -56,7 +57,11 @@ let minusBt = document.querySelectorAll('.minusBt');
function decrementQuantity() { function decrementQuantity() {
console.log(this); console.log(this);
this.previousElementSibling.previousElementSibling.innerHTML = Number(this.previousElementSibling.previousElementSibling.innerHTML) - 1; let qtyValue = Number(this.previousElementSibling.previousElementSibling.innerHTML);
if (qtyValue > 1) {
this.previousElementSibling.previousElementSibling.innerHTML = qtyValue - 1;
}
} }
addEventListenerList(minusBt, 'click', decrementQuantity); addEventListenerList(minusBt, 'click', decrementQuantity);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment