Answered step by step
Verified Expert Solution
Link Copied!

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 = parseInt(years.value, 10);
}
// Check for valid data:
if (type && type.value && years && (years >0)){
// TODO Add a switch statement to determine the base cost using the value of "type"
switch (type.value){
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 >1){
cost *=.80; //80%
}
let costElement = document.getElementById('cost');
// 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.getElementById('theForm').onsubmit = calculate;
}
window.onload = init;
"
Create Your Membership
Complete this form to calculate your membership. There's a 20%
discount if you enroll for more than one yearl
Years
Cost
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

The paleolithic age human life, short write up ?

Answered: 1 week ago