Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use a factory Function with the change calculator 1.Note that there are two JavaScript files for this application: the main JavaScript file (calculate.js) and the

Use a factory Function with the change calculator

1.Note that there are two JavaScript files for this application: the main JavaScript file (calculate.js) and the start of a library file (library_coin.js).

2. In the calculate.js file, note that three functions are supplied. The $ function. The calculateChange function that contains all of the code for the application. And an onload event handler that attaches this function to the click event of the Calculate button and sets the focus on the first field.

3.In the library_coin.js, note that just the strict declaration has been provided.

4. In the index.html file, add the script tag for the library file.

5. In the library file, code an object literal named coins that has a cents property and two methods:

The isValid method should determine whether the cents property is valid.

The getNumber method should accept a divisor parameter (like 25 for quarters), calculate the number of coins of that type that are required, update the cents property with the remaining cents, and return the number of coins

7.. Change the code in the calculate.js file to use the object returned by the factory function to validate the users entry and calculate the number of coins.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions