var n = $("input[name^= 'card']").length;
Here is what the above code is Doing:
1. We’re creating a variable called n that is equal to the number of elements with the name attribute that starts with “card”.
2. We’re using the length property to get the number of elements.