How can I limit the sum total of an array in Javascript?

Hello,

I should preface this by saying I have little coding knowledge, but I hope someone can help me.

I am working to create a product page where customers can choose up to 6 chocolate truffles to create their own custom box. I thought the easiest way to accomplish this is through line-item properties, and as long as the customer only selects 6 chocolates, it works great.

The issue is, there isn’t any limit to how many chocolate truffles a person can select. Could someone offer me guidance on limiting the total sum of chocolates in the array I set up? My hope is after selecting 6 Champagne Chocolate Truffles, customers won’t have the option to change any of the other fields.

here is a link to my preview store: https://mrdjgrnerjfzoy5c-55407378621.shopifypreview.com/products_preview?preview_key=0a6be3c371fcc6dd5f3e695dbad68de4

And here is the code I used to set up the line item properties:


  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

   

_*Please Choose 6 Truffles_

Total : 

Hi @RyanLundberg ,

I see your issue. You can try the code below


  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

  
  

   

_*Please Choose 6 Truffles_

Total : 

Thank you so much for your help, I really appreciate it.