• Resolved bergerlaw

    (@bergerlaw)


    Can while loops be used in the editor? I’ve tried inside of a function, but it creates an error on the site and kills the page. Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @bergerlaw

    Yes of course, you can use all valid javascript code.

    Please, describe your equation.

    Best regards..

    Thread Starter bergerlaw

    (@bergerlaw)

    So it’s javascript, not php?

    Thread Starter bergerlaw

    (@bergerlaw)

    I’m trying to create a calculator that determines how long it will take to pay off a credit card making just the minimum payment. The trick is that as the balance gets lower, so does the minimum payment. So I wrote a while loop that I thought would handle this. It’s not working (no results at all and the page dies); perhaps I should try in a code editor that shows errors in the code if any.

    Plugin Author codepeople

    (@codepeople)

    Hello @bergerlaw

    If you are implementing the client side equation, you should to use javascript, but if you are implementing server side equations using the “SERVER SIDE EQUATIONS” add-on, then the programming language to use would be PHP.

    Note, that pressing the “Advanced Equations Editor” in the settings of calculated field would be loaded a code editor that checks the errors.

    Best regards.

    Thread Starter bergerlaw

    (@bergerlaw)

    Thank you. It’s interesting that I have been using the Advanced Equations Editor, it doesn’t show any errors, but it’s still not working. I’ll keep trying.

    Plugin Author codepeople

    (@codepeople)

    Hello @bergerlaw

    If you need additional help, do not hesitate in include your equation’s code.

    Best regards.

    Thread Starter bergerlaw

    (@bergerlaw)

    Here was my first attempt:

    (function() {
    var balance = fieldname2;
    var monthstopayoff = 0;
    var totalinterest = 0;
    var interestrate = fieldname3 / 100 / 12;
    while (balance > 0) {
        var monthinterest = balance * interestrate;
        totalinterest += monthinterest;
        balance -= (balance * .01);
        monthstopayoff++;
    }
    return monthstopayoff;
    })();

    Note that fieldname2 is the loan balance. I was hardcoding some numbers just to try to get it to work. Ultimately I’m going to want to display how long to pay off the debt and total interest paid.

    Plugin Author codepeople

    (@codepeople)

    Hello @bergerlaw

    You don’t have any parser error in your equation, it is an execution error. The loop in your equation is infinite, because the following piece of code, will never be zero:

    balance -= (balance * .01);

    Best regards.

    Thread Starter bergerlaw

    (@bergerlaw)

    Of course! Once the balance gets to $25 for most credit cards, that becomes the final payment. Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘While Loop’ is closed to new replies.