Due Tonight! JavaScript code: What’s wrong?


5 Responses to “Due Tonight! JavaScript code: What’s wrong?”

  1. TheDude says:

    I’m basing this of my minimal knowledge of code, but isn’t there meant to be an opening bracket?

    {code code code code
    }

  2. Kevin says:

    i didn’t dig too deeply, but this line of code looks improper:

    while (balance !== 0) {

    it should be:

    while (balance != 0) {

  3. Ron says:

    Check your JS at the online Lint utility for JS:

    http://www.javascriptlint.com/online_lint.php

    Keep making corrections, then recheck until correct.

    Ron

  4. MichaelInScarborough says:

    This is just a guess from start reading into your code. There is only one condition, under which balance becomes 0:

    if((balance< =0.01) && (balance >=-0.01)){
    balance = 0;

    Otherwise balance is set as:
    balance = simulatePayments(amount, years, interest, monthlyPayment);

    So what you could do is to output the result of the simulatePayments function and determine, whether or not your break condition

    if((balance< =0.01) && (balance >=-0.01)){
    balance = 0;

    will ever be met.

    My guess is: No.
    ——
    balance = simulatePayments(amount, years, interest, monthlyPayment);
    The problem is that neither amount, nor years, nor interest, nor monthlyPayment are ever changing.
    —–
    in function simulatePayments, before you enter the while loop do the following:
    amt /= 1.0;
    W/o knowing much more about the logic: This helps that amt is recognized as a number. In my test script the output was a text
    Hope that helps!!!!

  5. Ratchetr says:

    I ran it in FF, yes it gets hung in a loop. Firebug to the rescue :-)

    It gets hung in this loop:
    while (amt > 0)
    amt += (amt * monthlyInterestFraction) – monthPay;

    It’s possible for the algorithm to guess a monthly pay value that’s lower than the monthly interest due…Negative Amortization…Amount due is always > 0…infinite loop.

    I don’t know if this is a true flaw in the algorithm, or just something caused by round off error in the math.

    You should be able to detect it easily enough: if monthlyInterestFraction < monthPay. But you’ll need to refactor the code a bit to handle that case.

    Analyzed by a human brain….but with a lot of help from Firebug ;-)

Leave a Reply

*


Celebrity Sex Tapes | Kim Kardashian Sex Tape