Cognizant Hands-on - Fixed And Reducing Interest Loan Estimator.

 

Fixed And Reducing Interest Loan Estimator

The Olympus Bank requires a Fixed and Reducing Interest Loan Estimator for the ease of it’s customers. The customers are asked to fill a form regarding their loan details. The customers can know about the Total Payment, Total Interest and the Monthy EMI to be paid for the loan taken based on both the Fixed and Reducing Interest.

Concept covered:  JavaScript Deep Dive – Math, number, function

The following are the screenshots for Fixed And Reducing Interest Loan Estimator

     

         

 Use the Label Name and the Component Id as given. The Component Id can be given in any case (Upper case or Lower case or Mixed case).All the necessary attributes for the Components should be given.

The Component Id should be specified for each HTML Component. If the Component Id is not provided for a HTML component, the marks will not be provided for this component.

All Tags, Elements and Attributes should conform to HTML5 Standards. All the fields are mandatory.

Provide the details as given in the table below.

Req. #

Req. Name

Req. Description

1

Design a Web page “Fixed And Reducing Loan Estimator” with the specified fields.


Label Name

Component  Id

(Specify it for the “id” attribute)

Description

Principal Loan Amount (Rs.)

principalAmount

To enter the principal amount for the loan.

Design Constraints:

The text “Principal Amount should appear by default.

 It should be mandatory.

Interest Rate (%)

interestRate

To enter the interest rate percentage.

Design Constraints:

The text “Interest Per Annum should appear by default.

It should be mandatory.

Tenure (in months)

tenure

To enter the tenure in months.

Design Constraints:

The text “Tenure in Months should appear by default.

It should be mandatory.

Estimate

Estimate

The input type button must be used.

NOTE: The text highlighted in bold in the Description needs to be implemented in the code to complete the web page design.

 

3

Use JavaScript for displaying the calculated EMI, Total Payment and Total Interest for both the Fixed And Reducing Loan Interest

 

Use JavaScript for displaying the calculated EMI, Total Payment and Total Interest for both the Fixed And Reducing Loan Interest

When the customer enters the valid values and clicks the “Estimate” button, the Reducing Interest Loan is displayed as  follows:

The result should be displayed as

“totalInterest” in a output tag with  id  “tInterest”.  

“totalPayment” in a output tag with  id  “tPayment”.  

 “EMI” in a output tag with  id  “EMI”.  

The Fixed Interest Loan is displayed as   follows:

 “totalInterest” in a output tag with  id  “tInterestFixed”.  

“totalPayment” in a output tag with  id  “tPaymentFixed”.  

 “EMI” in a output tag with  id  “EMIFixed”.  

Note: Use the getElementsByName() or getElementById()  function to retrieve the values.

4

form  Tag  with attribute onsubmit

form Tag is already given in the code template. Do not change the code template and do the coding as per the requirements and specification.

Make sure that the onclick attribute in the buttoncomponent with id=”Estimate” is invoking the JavaScript function like “EstimateReducingInterestLoan ()".

For the Reducing Interest Loan:

The EMI is calculated using the following formulae:

EMI = P * R * ( (1 + R)^N / ((1 + R)^N - 1) )

where P -> Principal amount

   R -> rate of interest per month = (r/100) / 12

   r -> rate of Interest per annum

   N -> tenure in months.

Use toFixed() function to display only two numbers after the decimal point in the calculated EMI.

For Example, the EMI is calculated as follows:

  P = Rs. 1,00,000

  r = 10%  R = (10/100) / 12

  N = 24 months           

  EMI is Rs.4614.49

The Total Payment is calculated using the following formulae:

totalPayment = EMI * tenure_months

The Total Interest is using the following formulae:

totalInterest = totalPayment – principalAmount

For the Fixed Interest Loan:

The Total Interest is using the following formulae:

totalInterest =  principalAmount * interestRate/100 * tenure_years

The Total Payment is calculated using the following formulae:

totalPayment = principalAmount + totalInterest

The EMI is calculated using the following formulae:

EMI = totalPayment / (tenure_years * 12)

Use toFixed() function to display only two numbers after the decimal point in the totalInterest, totalPayment and the calculated EMI.

 



SOLUTION:
ReducedInterestEstimate.html
<html lang="en">
<head>
    <title>Reducing Interest Loan Estimation</title>
    <style type="text/css">
        h2 {
            text-align: center;
            color: #FF0000;
            font-style: italic;
            font-weight: bold;
        }

        table {
            text-align: left;
            background-color: #FFE77A;
            padding: 10px;
        }

        thead {
            text-align: center;
        }

        #tablemain {
            margin-left: 35%;
        }

        #Estimate {
            background-color: #F1F334;
            color: #000000;
            font-size: 15px;
            height: 35px;
            width: 100px;
        }
    </style>
</head>
<body>
<h2>Reducing Interest Loan Estimation</h2>
<table id="tablemain">
    <tbody>
    <tr>
        <td>
            <table>
                <tbody>
                <tr>
                    <td>
                        <label for="principalAmount">Principal Loan Amount (Rs.)</label>
                    </td>
                    <td>
                        <input type="text" id="principalAmount" placeholder="Principal Amount" required>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="interestRate">Interst Rate (%)</label>
                    </td>
                    <td>
                        <input type="text" id="interestRate" placeholder="Interest Per Annum" required>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label for="tenure">Tenure (in months)</label>
                    </td>
                    <td>
                        <input type="text" id="tenure" placeholder="Tenure in Months" required>
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td align="left" style="padding: 10px">
                        <input id="Estimate" type="button" value="Estimate" onclick="EstimateReducingInterestLoan()">
                    </td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <table border="1">
                <caption><b>Loan Estimation</b></caption>
                <thead>
                <tr>
                    <th>Details</th>
                    <th>Reducing Interest Loan</th>
                    <th>Fixed Interest Loan</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>Total Interest Rs.</td>
                    <td>
                        <output id="tInterest"></output>
                    </td>
                    <td>
                        <output id="tInterestFixed"></output>
                    </td>
                </tr>
                <tr>
                    <td>Total Payment Rs.</td>
                    <td>
                        <output id="tPayment"></output>
                    </td>
                    <td>
                        <output id="tPaymentFixed"></output>
                    </td>
                </tr>
                <tr>
                    <td>Monthly EMI Rs.</td>
                    <td>
                        <output id="EMI"></output>
                    </td>
                    <td>
                        <output id="EMIFixed"></output>
                    </td>
                </tr>
                </tbody>
            </table>
        </td>
    </tr>
    </tbody>
</table>
<script src="Estimation.js"></script>
</body>
</html>

Estimation.js
const _principalAmount = document.getElementById("principalAmount");
const _interestRateYear = document.getElementById("interestRate");
const _tenureMonth = document.getElementById("tenure");

function getEmiReducing(P, N, R) {
    return (P * R * (Math.pow((1 + R), N) / (Math.pow((1 + R), N) - 1)));
}

function EstimateReducingInterestLoan() {
    calculateEMI();
    totalPayment();
    totalInterest();
    EstimateFixedInterestLoan();
}

function EstimateFixedInterestLoan() {
    const principalAmount = Number(_principalAmount.value);
    const interestRateYear = Number(_interestRateYear.value);
    const tenureMonth = Number(_tenureMonth.value);

    const totalInterestFixed = principalAmount * interestRateYear * tenureMonth / 1200;
    const totalPaymentFixed = principalAmount + totalInterestFixed;
    const emiFixed = totalPaymentFixed / tenureMonth;

    document.getElementById("tInterestFixed").innerHTML = Number(totalInterestFixed).toFixed(2).toString();
    document.getElementById("tPaymentFixed").innerHTML = Number(totalPaymentFixed).toFixed(2).toString();
    document.getElementById("EMIFixed").innerHTML = Number(emiFixed).toFixed(2).toString();
}

function reducingLoan() {
    const principalAmount = Number(_principalAmount.value);
    const interestRateYear = Number(_interestRateYear.value);
    const interestRateMonth = Number(interestRateYear / 1200);
    const tenureMonth = Number(_tenureMonth.value);

    const emiReducing = getEmiReducing(principalAmount, tenureMonth, interestRateMonth);
    const totalPaymentReducing = tenureMonth * emiReducing;
    const totalInterestReducing = totalPaymentReducing - principalAmount;

    return {
        emiReducing: emiReducing,
        totalPaymentReducing: totalPaymentReducing,
        totalInterestReducing: totalInterestReducing
    };
}

function calculateEMI() {
    const emiReducing = reducingLoan().emiReducing;
    document.getElementById("EMI").innerHTML = Number(emiReducing).toFixed(2).toString();
}

function totalPayment() {
    const totalPaymentReducing = reducingLoan().totalPaymentReducing;
    document.getElementById("tPayment").innerHTML = Number(totalPaymentReducing).toFixed(2).toString();
}

function totalInterest() {
    const totalInterestReducing = reducingLoan().totalInterestReducing;
    document.getElementById("tInterest").innerText = Number(totalInterestReducing).toFixed(2).toString();
}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.