Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: undefined!! help javascript

  1. #1
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default undefined!! help javascript

    how to i make it not say undefined as an answer?

    <HTML>
    <HEAD>
    <TITLE> BAD CREDIT </TITLE>
    <SCRIPT type="text/javascript">
    function monthlyRate () {
    var price =
    parseFloat(document.getElementById("price").value);
    var interest =
    parseFloat(document.getElementById("interest").value);
    var pay=
    parseFloat(document.getElementById("pay").value);
    if (isNaN(price) || isNaN(interest) || isNaN(pay)) {
    return;
    }


    price.toFixed(2)
    var monthrate = interest / 100 ;
    monthrate = monthrate + 1 ;
    monthrate = ((Math.pow(1 + interest , 1/12)) - 1);

    var monthly = monthrate;
    var bill = "+ price +" ;
    var month = 0;


    while ( bill >= pay ) {
    bill = price - pay ;
    bill = bill * (1 + monthly);
    price = bill ;

    }
    if ( bill < pay ) {
    var totalamount = pay * month + bill ;

    }

    document.getElementById("amount").value = totalamount;



    }


    </SCRIPT>
    </HEAD>
    <BODY>
    Enter the purchase price for the item you are interested in buying: <input onchange=monthlyRate() size=13 type=text id=price /><br/>
    Enter the annual interest rate on your credit card: <input onchange=monthlyRate() size=13 type=text id=interest /><br/>
    Enter the amount of money you plan to pay towards you credit card balance each month: <input onchange=monthlyRate() size=13 type=text id=pay /><br/>
    The amount you actually spent is: <input size=5 type=text id=amount /><br/>




    </BODY>
    </HTML>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Its saying undefined because here:
    Code:
    if ( bill < pay ) {
    var totalamount = pay * month + bill ; 
    
    }
    It is getting defined, but obviously bill isn't less than pay, so it's not being defined.
    Jeremy | jfein.net

  3. #3
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    how would you suggest i fix this?

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Well, first of all. I suggest learning some more basic Javascript. Like Javascript Concatenation.

    I don't think:
    Code:
    var bill = "+ price +" ;
    Is valid.
    Jeremy | jfein.net

  5. #5
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok well if i take "+price+" away, i don't get anything at all as an answer. just a blank textbox... so the computer doesn't know what goes under var bill ..

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Do:
    Code:
    var bill = price;
    Jeremy | jfein.net

  7. #7
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok i did and got an alert, which i clicked on "debug" ... and got..

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    If bill isn't greater than pay, what should the value of totalamount be?
    Jeremy | jfein.net

  9. #9
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    a negative?

  10. #10
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    im not sure what you mean. im sorry.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •