Skip to content

Commit

Permalink
Create script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fswaleh authored Feb 27, 2023
1 parent f460160 commit 86af76d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function compute()
{
var principal = document.getElementById("principal").value;
var rate = document.getElementById("rate").value;
var years = document.getElementById("years").value;
var interest = principal * years * rate / 100;
var amount = parseInt(principal)+ parseFloat(interest);
var result = document.getElementById("result");
var year = new Date().getFullYear() + parseInt(years);

if(principal <= 0){
alert("Please enter a positive number!");
document.getElementById("principal").focus();

} else {
result.innerHTML = "If you deposit $" + "<mark>" + principal + "</mark>" + ",\<br\> at an interest rate of " + "<mark>" + rate + "%" + "</mark>" + "\<br\> You will receive an amount of $" + "<mark>" + amount + "</mark>" + ",\<br\> in the year " + "<mark>" + year + "</mark>" + "\<br\>";
}

}

function updateRate() {

var rateval = document.getElementById("rate").value;
document.getElementById("rate_val").innerText = rateval;

}

0 comments on commit 86af76d

Please sign in to comment.