Skip to content

Commit

Permalink
Added Savings Goal Calculator (Rakesh9100#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manav173 authored Jul 12, 2024
1 parent 5588f2d commit 96b2014
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Calculators/Savings-Goal-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# <p align="center">Savings Goal Calculator</p>

## Description :-

This calculator helps you determine how much you need to save each month to reach your savings goal. By providing the total savings goal, current savings, and the time period (in months), the calculator computes the required monthly savings to achieve the goal.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Formula Used :-

The formula for calculating the required monthly savings is:

Monthly Savings = (Savings Goal − Current Savings) / Time Period

Where:

Savings Goal is the total amount you want to save.
Current Savings is the amount you have already saved.
Time Period is the number of months you plan to save.

## Screenshots :-

![image](https://github.com/user-attachments/assets/658fdabe-f5d0-4b6d-8ad2-c7bcd23fcf04)
35 changes: 35 additions & 0 deletions Calculators/Savings-Goal-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Savings Goal Calculator</title>
</head>

<body>
<div class="calculator-container">
<h1>Savings Goal Calculator</h1>
<div class="input-container">
<label for="goalAmount">Savings Goal Amount (INR):</label>
<input type="number" id="goalAmount" required>
</div>
<div class="input-container">
<label for="currentSavings">Current Savings (INR):</label>
<input type="number" id="currentSavings" required>
</div>
<div class="input-container">
<label for="timePeriod">Time Period (Months):</label>
<input type="number" id="timePeriod" required>
</div>
<button type="button" onclick="calculateSavings()">Calculate</button>
<div class="result-container">
<div id="result">Monthly Savings Required: <span id="savingsResult" class="red">₹0.00</span></div>
</div>
</div>

<script src="script.js"></script>
</body>

</html>
20 changes: 20 additions & 0 deletions Calculators/Savings-Goal-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function calculateSavings() {
const goalAmount = parseFloat(document.getElementById('goalAmount').value);
const currentSavings = parseFloat(document.getElementById('currentSavings').value);
const timePeriod = parseInt(document.getElementById('timePeriod').value);

if (isNaN(goalAmount) || isNaN(currentSavings) || isNaN(timePeriod)) {
document.getElementById('result').textContent = 'Please fill in all fields correctly.';
return;
}

if (goalAmount <= currentSavings) {
document.getElementById('result').textContent = 'You have already reached your savings goal!';
return;
}

const amountNeeded = goalAmount - currentSavings;
const monthlySavings = amountNeeded / timePeriod;

document.getElementById('result').textContent = `You need to save ₹${monthlySavings.toFixed(2)} per month to reach your goal.`;
}
71 changes: 71 additions & 0 deletions Calculators/Savings-Goal-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(to right, #f48a8a, #a3dbf5);
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.calculator-container {
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 500px;
text-align: center;
}

h1 {
color: #333;
}

.input-container {
margin-bottom: 15px;
}

label {
display: block;
margin-bottom: 5px;
color: #555;
}

input {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 5px;
box-sizing: border-box;
}

button {
background-color: #4caf50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}

button:hover {
background-color: #45a049;
transform: scale(1.05);
transition: 0.2s ease-in-out;
}

.result-container {
margin-top: 20px;
}

#result {
font-size: 18px;
font-family: 'Courier New', Courier, monospace;
font-weight: bold;
color: #333;
}

.red {
color: #f44336;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3632,6 +3632,20 @@ <h3>Calculates the total amount we can save over a specified period by making mo
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Savings Goal Calculator</h2>
<h3>Determines how much you need to save each month to reach your savings goal.</h3>
<div class="card-footer">
<a href="./Calculators/Savings-Goal-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Savings-Goal-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Sentence Counter Calculator</h2>
Expand Down

0 comments on commit 96b2014

Please sign in to comment.