Question: 'use strict'; / / membership.js / / This script calculates the cost of a membership. / / Function called when the form is submitted. /
'use strict';
membership.js
This script calculates the cost of a membership.
Function called when the form is submitted.
Function performs the calculation and returns false.
function calculate
TODO declare a variable named 'cost' to store the total cost:
TODO lookup the type and years input elements with DOM getElementById
TODO Convert the year to a number see parseInt
if years && years.value
years parseIntyearsvalue, ;
Check for valid data:
if type && type.value && years && years
TODO Add a switch statement to determine the base cost using the value of "type"
switch typevalue
case 'basic':
break;
case 'premium':
break;
case 'gold':
break;
case 'platinum':
break;
TODO Update cost by multiplying number of years
Discount multiple years
if years
cost ;
let costElement document.getElementByIdcost;
TODO convert cost to a number and then format to decimal places see Number.toFixed
TODO update the value property of 'costElement' to the calculated cost
Return false to prevent submission:
return false;
function init
document.getElementByIdtheFormonsubmit calculate;
window.onload init;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
