From 92ea893cfc6ea15937175b72dae59181cb8220cf Mon Sep 17 00:00:00 2001 From: ashley burns Date: Mon, 11 Mar 2024 12:11:39 -0400 Subject: [PATCH] Create simple interest calculator Signed-off-by: ashley burns --- .gitignore | 1 + index.html | 52 +++++++++++++++++++++++++++++++++++++++++----------- script.js | 43 ++++++++++++++++++++++++++++++++++++++----- style.css | 21 +++++++++++++++++---- 4 files changed, 97 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index b6e47617d..1b77d315a 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,4 @@ dmypy.json # Pyre type checker .pyre/ +.vscode/settings.json diff --git a/index.html b/index.html index 8a580ffb3..862d68abb 100644 --- a/index.html +++ b/index.html @@ -1,16 +1,46 @@ + - + + Simple Interest Calculator - - - -

Simple Interest Calculator

+ + - Amount
- Rate
- No. of Years
- Interest :
+ +
+

Simple Interest Calculator

- - + Amount
+ Rate + +
+ 10.25 %
+ No. of Years
+ + + + + + + + + + + + + Interest :
+ + + +
+
© This Calculator belongs to --Ashley Burns--
+ diff --git a/script.js b/script.js index 7adfb78be..b93da1e0e 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,39 @@ -function compute() -{ - p = document.getElementById("principal").value; - +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("Enter a positive number!"); + document.getElementById("principal").focus(); + } else { + result.innerHTML = + "If you deposit $" + + "" + + principal + + "" + + ",
at an interest rate of " + + "" + + rate + + "%" + + "" + + "
You will receive an amount of $" + + "" + + amount + + "" + + ",
in the year " + + "" + + year + + "" + + "
"; + } +} + +function updateRate() { + var rateval = document.getElementById("rate").value; + document.getElementById("rate_val").innerText = rateval; } - \ No newline at end of file diff --git a/style.css b/style.css index 8a6b03574..f9e21a9ba 100644 --- a/style.css +++ b/style.css @@ -1,4 +1,17 @@ -body {background-color:tan;} -h1{color:green;} - - +body { + background-color: black; + font-family: Arial; + color: white; +} +h1 { + color: gray; + font-family: Verdana; +} +.maindiv { + background-color: white; + color: black; + width: 300px; + padding: 20px; + border-radius: 25px; + text-align: center; +}