Answered step by step
Verified Expert Solution
Question
1 Approved Answer
'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;
Create Your Membership
Complete this form to calculate your membership. There's a
discount if you enroll for more than one yearl
Years
Cost
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started