Hi! Need help here.
I'm making a loan processing system using javascript. But I can't get through with the right outputs because I cant make one formula right. Here are the specifications and requirements:
Input:
name of borrower
loan amount
interest rate (% per annum)
term of loan (years)
Output:
Name of borrower
Loan amount
Interest rate
Term
Rebate (1% if years/term is less than 5 years)
Amount due (future value only... or if term is less than 5 years, F minus rebate)
variables:
P=present value (loan amount)
r=interest rate
n=term of loan in years
F=future value (amount due after term)
Solutions:
F= P(1+r)^n
rebate= Future value * 0.01
Amount due= if n>=5, then F, else F*0.99
Code:
<script type="text/javascript">
//x=prompt("Enter name of borrower: ");
//alert("Name of borrower: "+x);
name=prompt("Enter name of borrower: "," ");
P=prompt("Enter loan amount: "," ");
r=prompt("Enter interest rate (% per annum): ", " ");
n=prompt("Enter term of loan (year): ", " ");
F=P*Math.pow(1+r, n);
AmtDue=(n>=5)? F: F*0.99;
document.write("Name of borrower: " +name);
document.write("<br> Loan amount: PhP" +P);
document.write("<br> Interest rate: " +r +'% per annum');
document.write("<br> Term: " +n +' years <hr>');
document.write("<br> Rebate: PhP " +rebate);
document.write("<br> Amount due: PhP " +AmtDue);
</script>
I'm having problems with the solution for F(Future value)... I also used Math.pow for the exponent of 1+r which is n(term or year).When I test it with these values, it displays the wrong Rebate and Amount Due: Test Values:
loan amount(P)= 100
interest rate(r)= 5
term of loan (n)= 2
Please help me with this... I couldn't get the correct output/results because of the equation or solution for Future value(F)... Please, and thank you in advance...
I knew the math already when I started to learn javascript. Most of it is "monkey see, monkey do" from my textbook but I added the years and months option as well as a PI table later. It may be helpful.
yah, that is the correct answer. Last night, when i tested the thing with the given values, it gave me a Rebate value of more than 10,000 and an Amount Due value of more than 13,000... I have no idea where those answers came from... Now, when I tested it again, the two didn't show any values anymore... And even the words weren't there anymore. It gave me only the output of:
Loan amount: 100
Interest rate: 5
Term: 2
it, ended there... no more rebate and amount due... even the words "Rebate:" and "Amount Due:" were no longer displayed...
I tried the r= parseInt(r); u gave but it still wouldn't show up... I didn't make any revisions last night so I'm wondering why the rebate and amount due wouldn't show up this time. What do you think is wrong? Do you have any suggestions for an alternative code?
According to what i have learned, values are always read as variables, not strings... values that are recognized as strings are those enclosed within the "" sign... Not quite sure... But based on the entire time i've been using values, if they are just typed as mere letters without a "" symbol it is read by javascript as variable to set a value or declare something. I guess so...
Anyways, I tried to do the code you gave i am having a new problem. Last night I was still testing it and it was working fine except for the calculations of the Rebate and Amount Due. But just now, when i tried to test the thing again, it didn't display the Amount Due and Rebate... including the words "Rebate:" and "Amount Due:"... So even if i tried your suggested code, I still couldn't see if it fixed the math problem.
What do you think might be wrong with it?... Do you have any suggested alternative codes aside from the code I did?...
i think the loan processing system that i am doing works in a different way yours does. And i should not do any additional inputs or outputs than those stated in the requirements because it is a workshop given by our professor for school. I have no choice but to stick to the given input requirements.
But thanks for the help! I really appreciate it! Good day!
All input read from the user is a string until converted. If the string happens to evaluate to a number it can be used as an operand but not involving the + operator.
Clueful, oh yah... sorry bout that... I thought you were talking bout the coding... I just understood after reading your reply that you meant inputs...
By the way, thanks for suggesting the error console!... its javascript console in the browser i am using (Google Chrome)... All this time i forgot to state the value and formula of rebate! stupid me! lol... That's why rebate and amount due wont display!... Really stupid me!!!!
Bookmarks