Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chapter 10 discusses JavaScript event handling. In this assignment you will use

ID: 3854788 • Letter: C

Question

Chapter 10 discusses JavaScript event handling. In this assignment you will use the onclick event for a form button to make calculations based on the user input. Below is a screen capture of your expected output. Don't forget to download the assignment data files posted below.

HINT: To extract the user input from a form element, try: var cents = document.getElementById("myCents").value if "myCents" is the value assigned to the ID attribute for the HTML input element that is uded to create the text box where the user enters thier number. Example: <input type = "text" id = "myCents" /> .

Operation

This application allows the user to enter a number of cents from 0 to 99.

When the calculate button is clicked (the event), this application displays the fewest number of coins for each denomination needed to add up to the amount of cents entered by the viewer.

Change Calculator 94 Calculate Enter number of cents (0-99): Quarters3 Dimes Nickels: 1 Pennies. 4

Explanation / Answer

Code on main html page:

<html>

<head>

</head>

<body>

<form>

Enter number of cents(0-99) <input type="text" id="val"> <input type="button" name="Calculate">

Quarters:<input type="text" id="quarters"><br>

Dimes:<input type="text" id="dimes"><br>

Nickels:<input type="text" id="nickels"><br>

<Pennies:<input type="text" id="pennies"><br>

</form>

<src="code.js">

</body>

</html>

Code in code.js page:

function calc()

{

var a,b,c,d;

a=document.forms[0].getElementById["val"].value;

b=a/25;

document.forms[0].getElementById["quarter"].value=b;

a=a-b*25;

c=a/10;

a=a-10*c;

document.forms[0].getElementById["dimes"].value=c;

d=a/5;

document.forms[0].getElementById["nickels"].value=d;

a=a-5*d;

document.forms[0].getElementById["pennies"].value=a;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote