Here's my script :
function itemQuantityHandler(operation, cart_item) {
  var v = cart_item.quantity;
  //add one
  if (operation === 'add' && v < settings.productBuyLimit) {
    v++;
  }
  //substract one
  if (operation === 'subtract' && v > 1) {
    v--;
  }
  //update quantity in shopping cart
  $('.item-quantity').text(v);
  //save new quantity to cart
  cart_item.quantity = v;
}
What I need is to increase v (cart_item.quantity) by more than one. Here, it's using v++, but it's only increasing by 1. How can I change this to make it increase by 4 every time I click on the plus icon?
I tried
v++ +4
But it's not working.
A for loop doesn't increment anything. Your code used in the for statement does.
A program can increment by 1 the value of a variable called c using the increment operator, ++, rather than the expression c=c+1 or c+=1. An increment or decrement operator that is prefixed to (placed before) a variable is referred to as the prefix increment or prefix decrement operator, respectively.
The most simple way to increment/decrement a variable is by using the + and - operators. This method allows you increment/decrement the variable by any value you want.
Adding 1 to a variable is called incrementing and subtracting 1 from a variable is called decrementing. increment and decrement operators work only with integer variables -- not on floating point variables or literals. the C++ compiler is controlling the execution of the prefix and postfix operators.
Use a compound assignment operator:
v += 4;
                        Use variable += value; to increment by more than one:
v += 4;
It works with some other operators too:
v -= 4;
v *= 4;
v /= 4;
v %= 4;
v <<= 1;
v >>= 4;
                        To increase v by n: v += n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With