Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Trying to make Javascript to make change(money)

tonybar2tonybar2 Posts: 72Member
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">








Making change

What's Your Change

Enter the change total:




The correct change is

Dollars:

Quarters:

Dimes:

Nickels:

Pennies:





I am now a JavaScript writer.






It works fine, except I cannot get the dollars to work, anyone know what I am doing wrong?

Comments

  • CyGuyCyGuy Posts: 312Member

    :
    : It works fine, except I cannot get the dollars to work, anyone know
    : what I am doing wrong?
    :

    You did a good job on the program; the problem is that the value submitted is not read into the [italic]remain[/italic] until after the quarters are calculated:

    [code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    "http://www.w3.org/TR/html4/loose.dtd">








    Making change

    What's Your Change

    Enter the change total:




    The correct change is

    Dollars:

    Quarters:

    Dimes:

    Nickels:

    Pennies:




    [/code]
  • tonybar2tonybar2 Posts: 72Member
    : I still cannot get this thing to work correctly, I would also like to add
    fives, tens, and twenties, any help would be appreciated the code I have now is not doing the dimes right?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">








    Making change

    What's Your Change


    Enter the change total:






    The correct change is

    Dollars:

    Quarters:

    Dimes:

    Nickels:

    Pennies:






    I am now a JavaScript writer.





  • mburton06mburton06 Posts: 3Member
    function addFields(form) {

    var strCents = prompt("Please enter the number of cents", "Type number here");
    var cents = parseInt(strCents);
    var quarters = Math.floor(cents / 25);
    var dimes = Math.floor((cents % 25) / 10);
    var nickels = Math.floor(((cents % 25) % 10) / 5);
    var pennies = cents % 5;
    alert(cents + " cents is comprised of:
    " + quarters + " quarter(s)
    " + dimes + " dime(s)
    " + nickels + " nickel(s)
    " + pennies + " pennies
    ");

    }

    Here is what I have model the dollars after the pennies, nickels, dimes etc. It worked for me
  • mburton06mburton06 Posts: 3Member
    function addFields(form) {

    var strCents = prompt("Please enter the number of cents", "Type number here");
    var cents = parseInt(strCents);
    var quarters = Math.floor(cents / 25);
    var dimes = Math.floor((cents % 25) / 10);
    var nickels = Math.floor(((cents % 25) % 10) / 5);
    var pennies = cents % 5;
    alert(cents + " cents is comprised of:
    " + quarters + " quarter(s)
    " + dimes + " dime(s)
    " + nickels + " nickel(s)
    " + pennies + " pennies
    ");

    }

    Here's what I have, model dollars on pennies, dimes
  • mburton06mburton06 Posts: 3Member
    function addFields(form) {

    var strCents = prompt("Please enter the number of cents", "Type number here");
    var cents = parseInt(strCents);
    var quarters = Math.floor(cents / 25);
    var dimes = Math.floor((cents % 25) / 10);
    var nickels = Math.floor(((cents % 25) % 10) / 5);
    var pennies = cents % 5;
    alert(cents + " cents is comprised of:
    " + quarters + " quarter(s)
    " + dimes + " dime(s)
    " + nickels + " nickel(s)
    " + pennies + " pennies
    ");

    }

    Here's what I have, model dollars on pennies, dimes, nickels etc.
Sign In or Register to comment.