Calculate Compound Interest in JavaScript

 Calculate Compound Interest in JavaScript


HTML CODE

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table>
        <tr>
            <td>Enter Principle</td>
            <td>
                <input type="text" name="" id="p">
            </td>
        </tr>
        <tr>
            <td>Enter Time</td>
            <td>
                <input type="text" name="" id="t">
            </td>
        </tr>
        <tr>
            <td>Enter Rate </td>
            <td>
                <input type="text" name="" id="r">
            </td>
        </tr>
        <tr>
            <td>
                <button onclick="ci()">Enter</button>
            </td>
        </tr>
    </table>
    <div id="res"></div>
    <script src="code.js"></script>
</body>
</html>

JS CODE

function ci(){
    var p=document.getElementById("p").value;
    var t=document.getElementById("t").value;
    var r=document.getElementById("r").value;

    var amount = p*Math.pow(1+r/100,t);
    var ci=amount-p;
    document.getElementById("res").innerHTML="Amount = "+amount.toFixed(2)+
    "Compound Interest "+ci.toFixed(2);
}

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Make a GST Calculator using HTML and JavaScript

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java