-1

ISSUE

I am using a variable called var addedToCart = 0; . How to set a max and min value so that user cannot click more or less than the specified value and var addedToCart will not store the out of range value?

I want

When + icon clicked add value to addedToCart
When - icon clicked subtract value from addedToCart
but within specified range

Aman Chaudhary
  • 802
  • 3
  • 10
  • 27

1 Answers1

0

You can simply use if statement

var MIN = 0;
...
if(value > MIN){
  setState({
    addedToCart--;
  })
}

...

if(value < MAX){
  setState({
    addedToCart++;
  })
}
ikerfah
  • 2,612
  • 1
  • 11
  • 18