Question

?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:

Recycla Bin Cent 3C122-Wa. C/Users kmbar Desktopýchegg/cakulate_coins.js (Cetting Started)- Brackets File Edit Find View Navigate Debug Help Criain ScreenShare CSC122-Wa 1 ?hvar function ?id) { return docunent-FlentRyTd(id) ataFiles Cetting Staced HomSherc Cath Pin to Qui:k Capy Paste Mae Copy Delele Renam Nesw lpbcard orgariz0 -> ? | > This PC > Desktop > chegg Desktop ?^ Name Date mod Doauments Getig Stanteindex Pictures Cent Checkr FvenNumber WEB115 default /1/2018 V1/2018 OneDrwe Problems This PC A NtanKuw Network 3it itei selected 63 bytes

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the js code ::::

----------------------------------------------

var $ =function(id){

return document.getElementById(id);

}

function convertData(){

cents = $("cents").value;

cents = parseInt(cents);

noOfQ = parseInt(cents/25);

cents = cents%25;

noOfD = parseInt(cents/10);

cents = cents%10;

noOfN = parseInt(cents/5);

cents = cents%5;

noOfP = cents;

$("quarters").value = noOfQ;

$("dimes").value = noOfD;

$("nickels").value = noOfN;

$("pennies").value = noOfP;

}

need to assign this function call to onclick of button

so modify and add onclick to the button in html like below:

<input type="button" value="Calculate" id="calculate" onclick="convertData()">

output:

Add a comment
Know the answer?
Add Answer to:
?In this assignment you will use the onclick event for a form button to make calculations...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT