JSFiddle - React, Tailwind, and code Playground

by ChrisStanyon

HTML

<input type="checkbox" class="gifts custom-control-input" value="1">
<input type="checkbox" class="gifts custom-control-input" value="2" checked>
<input type="checkbox" class="gifts custom-control-input" value="4" checked>
<input type="checkbox" class="gifts custom-control-input" value="8" checked>

JavaScript

let gifts = document.getElementsByClassName("gifts");
let total = 0;

for(let i=0; i<gifts.length; i++) {
	total += gifts[i].checked ? +gifts[i].value : 0;
}

console.log(total);