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

Thread: help please

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

    Default help please

    can someone pleeeease help me with this javascript
    i have no idea what's wrong with it
    but i can load it up so there must be something wrong with it...

    <HTML>
    </HEAD>
    <TITLE> Last HOMEWORK </TITLE>
    <SCRIPT type="text/javascript">


    function monthlyRate (interest) {

    var rate = interest / 100;
    rate = rate + 1;
    rate = ((1 + interest) ^(1/12)) minus 1);
    return monthRate;
    }



    </SCRIPT>
    </HEAD>
    <BODY>
    <SCRIPT type="text/javascript">


    var price = parseFloat (prompt ( "What was the purchase price for the item you are interested in buying?"));
    var interest = parseFloat ( prompt ( "What is the annual interest rate on your credit card?"));
    var pay = parseFloat ( prompt ("How much do you plan to pay towards you credit card balance each month?"));

    var monthly = monthlyRate (interest);

    var bill = price;

    var month = 0;

    while (bill >= pay) {
    bill = price - pay
    bill = bill * (1 + monthRate)
    price = bill
    }
    if ( bill < pay) {
    var amount = pay * month + bill
    alert ("You have actually spend "+ amount +" on this item")
    }


    </BODY>
    </SCRIPT>
    </HTML>

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

    Default

    The operator '^' doesn't work in js.
    Use Math.sqrt().

    More info here.
    Jeremy | jfein.net

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

    Default ok done

    still doesn't work
    thanks though

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

    Default

    Here:
    Code:
    return monthRate;
    Shouldn't it be:
    Code:
    return rate;
    Still using the Math.sqrt.
    Jeremy | jfein.net

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

    Default ok

    ok. did that as well and still nothing. i used firebug and it said :

    missing ) in parenthetical
    [Break on this error] rate = (((1 + interest) Math.sqrt(1/12)) minus 1));\n
    javascri... 8.html (line 12)
    syntax error
    [Break on this error] </BODY>\n


    i have no idea what this means.

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

    Default

    I think it should be:
    Code:
    rate = (((1 + interest) Math.sqrt(1/12)) - 1);
    But I made a mistake, use Math.pow(a,b). See more info on the page above.
    Jeremy | jfein.net

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

    Default

    oh yes! you have a good eye
    but firebug still says the same thing...
    thanks for helping me btw

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

    Default

    Glad to help you so far, I hope you saw my edit about Math.pow.
    Please gimme all your code with the updated stuff.
    Jeremy | jfein.net

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

    Default here

    <HTML>
    <HEAD>
    <TITLE> Last HOMEWORK </TITLE>
    <SCRIPT type="text/javascript">


    function monthlyRate (interest) {

    var rate = interest / 100;
    rate = rate + 1;
    rate = (((1 + interest) Math.pow(1,12)) - 1));
    return Rate;
    }

    </SCRIPT>
    </HEAD>
    <BODY>
    <SCRIPT type="text/javascript">


    var price = parseFloat (prompt ( "What was the purchase price for the item you are interested in buying?"));
    var interest = parseFloat ( prompt ( "What is the annual interest rate on your credit card?"));
    var pay = parseFloat ( prompt ("How much do you plan to pay towards you credit card balance each month?"));

    var monthly = monthlyRate (interest);

    var bill = price;

    var month = 0;

    while (bill >= pay) {
    bill = price - pay
    bill = bill * (1 + monthRate)
    price = bill
    }
    if ( bill < pay) {
    var amount = pay * month + bill
    alert ("You have actually spend "+ amount +" on this item")
    }
    </BODY>
    </SCRIPT>
    </HTML>

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

    Default

    Well, I didn't spend time orgainizing it, but here:
    Code:
    <HTML>
    <HEAD>
    <TITLE> Last HOMEWORK </TITLE> 
    <SCRIPT type="text/javascript">
      function monthlyRate(interest) {
        var rate = interest / 100;
        rate = rate + 1;
        rate = (((1 + interest) + Math.pow(1, 12)) - 1);
        return rate;
      }
    </SCRIPT>
    </HEAD>
    <BODY>
    <SCRIPT type="text/javascript">
      var price = parseFloat(prompt("What was the purchase price for the item you are interested in buying?"));
      var interest = parseFloat(prompt("What is the annual interest rate on your credit card?"));
      var pay = parseFloat(prompt("How much do you plan to pay towards you credit card balance each month?"));
      var monthly = monthlyRate(interest);
      var bill = price;
      var month = 0;
      while (bill >= pay) {
        bill = price - pay
        bill = bill * (1 + monthly)
        price = bill
      }
      if (bill < pay) {
        var amount = pay * month + bill
        alert("You have actually spend " + amount + " on this item")
      }
    </SCRIPT>
    </BODY>
    </HTML>
    Jeremy | jfein.net

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
  •