var calculator = document.querySelector(“form”);
function extras() {
// Object vs Array
var extrasPricing = {
candles: 5,
inscription: 10,
decoration: 25,
special: 50
}
var extrasCost = 0;
var extras = document.getElementsByName(“extras”);
for (var i = 0; i < extras.length; i++) { if (extras[i].checked) { var val = extras[i].value; // Update here to add/remove value of checked item to previous checked item. extrasCost += extrasPricing[val]; } } return extrasCost; }function calculateTotal() { calculator.total.value = "$" + extras(); }function extras() { const extrasPricing = { candles: 5, inscription: 10, decoration: 25, special: 50, };let extrasCost = [...document.querySelectorAll('input[name=extras]:checked')] .map((el) => extrasPricing[el.value])
return extrasCost.length > 0 ? extrasCost.reduce((total, num) => total + num) : 0;
}
function calculateTotal() {
calculator.total.value = ‘$’ + extras();
}