onChange calculation

Hi,

I have been looking for ages for this code but had no luck.

Is there a way when multiple switches are clicked, I can total up the cost of each service and show the prices on the website?

For example I have roughly 100 variants for different repairs on different phone models but going to only use a couple for this:

User clicks:

iPhone 5g screen repair £x.xx
+
iPhone battery replacement £x.xx

Quote shows:

= £x.xx

You can create a variable of type number and for each switch that is clicked, add its value to that variable. i.e.:

let totalCount = 0;
$w(`Switch`).forEach(s => s.onChanged(() => totalCount += s.clicked ? 1 : 0));