I have an assignment due tomorrow night that calls for the student to develop an application that tells how many quarters, dimes, nickels, and pennies are needed to make change for any amount of change from 0 - 99 cents. As a hint it says: One way to get the results is to use the divide and modulus operators along with the parseInt method for truncation the results so they are whole numbers.

Here's what I have so far:

var $ = function (id) { return document.getElementById(id); } var make_change = function() { var cents = parseInt($("cents").value); quarters = 25; dimes = 10; nickels = 5; pennies = 1; var remainder = cents / quarters; remainder = parseInt(remainder.toFixed(1)); totalDimes =(cents % quarters) / dimes; totalDimes = parseInt(totalDimes.toFixed(1)); totalNickels = (cents % quarters) % dimes / nickels; totalNickels = parseInt(totalNickels.toFixed(1)); totalPennies = totalNickels % pennies; totalPennies = parseInt(totalPennies.toFixed(1)); $("quarters").value = remainder; $("dimes").value = totalDimes; $("nickels").value = totalNickels; $("pennies").value =totalPennies; } window.onload = function () { $("calculate").onclick = make_change; }

Here's my problem. (Well for starters). If the user enters values above 25, in multiples of 5, i.e, 25, 30, 35, 40, etc. the code returns the correct change. However, this is not the case if user enters say, 26, or 31, or 58, etc. I'm theorizing that I should be able to use modulus to get my value for pennies as I did here:

totalPennies = totalNickels % pennies;

But that doesn't cut it for integers that fall within 0 and 5. (1,2,3,4) nor integers between 5 and 10. I'm stomped here and I believe that I don't have enough programming knowledge under my belt to be able to express the math needed to be done on the pennies variable.

This is only my third Javascript application and the first two dealt with IF statements/Loops.

Also, since I haven't yet dealt with the part of the application that handles values less than 25, my question is...do I put those statements inside an IF statement? If so, is it possible to place an IF statement inside of the code that runs within the function

var make_change = function().

Lastly as previously stated, I sincerely apologize if I violated any forum rules.

Thanks.