-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f14ec06
commit ae08f2a
Showing
5 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# <p align="center">Perpetuity Calculator</p> | ||
|
||
## Description :- | ||
|
||
A simple and interactive tool to calculate the **present value (PV)** of a perpetuity, an infinite series of cash flows, using the formula: | ||
|
||
**PV = C / r** | ||
|
||
Where: | ||
- **PV** is the present value | ||
- **C** is the annual cash flow | ||
- **r** is the discount rate | ||
|
||
This tool makes financial calculations easier and helps users understand perpetuities better. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Features :- | ||
|
||
- **Perpetuity Calculation**: Input fields to calculate present value based on cash flow and discount rate. | ||
- **Reset Functionality**: Clear all fields and results with a single click. | ||
- **Error Handling**: Alerts users with meaningful error messages for invalid inputs. | ||
- **Tooltips**: User guidance on input requirements. | ||
- **Responsive Design**: Adapts to all devices for seamless usability. | ||
|
||
## Formula :- | ||
|
||
**Present Value = Cash Flow / Discount Rate** | ||
|
||
## Screenshots :- | ||
|
||
![image](https://github.com/user-attachments/assets/a68ff8ad-781a-4943-a125-4e1b2a57cf5a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!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>Perpetuity Calculator</title> | ||
</head> | ||
|
||
<body> | ||
<div class="calculator"> | ||
<h1>Perpetuity Calculator</h1> | ||
<p>Calculate the present value of an infinite series of cash flows.</p> | ||
|
||
<div class="input-section"> | ||
<label for="cashFlow">Annual Cash Flow (C):</label> | ||
<input type="number" id="cashFlow" placeholder="Enter cash flow" step="0.01"> | ||
<span class="tooltip">Example: 1000</span> | ||
|
||
<label for="discountRate">Discount Rate (r %):</label> | ||
<input type="number" id="discountRate" placeholder="Enter discount rate" step="0.01"> | ||
<span class="tooltip">Example: 5 (for 5%)</span> | ||
</div> | ||
|
||
<button id="calculateBtn">Calculate</button> | ||
<button id="resetBtn">Reset</button> | ||
|
||
<div id="output"> | ||
<h2>Result:</h2> | ||
<p id="presentValue">Present Value (PV): --</p> | ||
</div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
document.getElementById("calculateBtn").addEventListener("click", () => { | ||
const cashFlow = parseFloat(document.getElementById("cashFlow").value); | ||
const discountRate = parseFloat(document.getElementById("discountRate").value); | ||
|
||
if (isNaN(cashFlow) || cashFlow <= 0) { | ||
alert("Please enter a valid annual cash flow (greater than 0)."); | ||
return; | ||
} | ||
|
||
if (isNaN(discountRate) || discountRate <= 0 || discountRate >= 100) { | ||
alert("Please enter a valid discount rate (greater than 0 and less than 100)."); | ||
return; | ||
} | ||
|
||
const rateDecimal = discountRate / 100; | ||
const presentValue = cashFlow / rateDecimal; | ||
|
||
document.getElementById("presentValue").textContent = `Present Value (PV): ${presentValue.toFixed(2)}`; | ||
}); | ||
|
||
document.getElementById("resetBtn").addEventListener("click", () => { | ||
document.getElementById("cashFlow").value = ""; | ||
document.getElementById("discountRate").value = ""; | ||
document.getElementById("presentValue").textContent = "Present Value (PV): --"; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background: linear-gradient(135deg, #2b5876, #4e4376); | ||
color: white; | ||
text-align: center; | ||
margin: 0; | ||
padding: 0; | ||
height: 100vh; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.calculator { | ||
background-color: rgba(0, 0, 0, 0.8); | ||
border-radius: 15px; | ||
padding: 20px 30px; | ||
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
h1 { | ||
margin-bottom: 10px; | ||
font-size: 26px; | ||
color: #84cef5; | ||
} | ||
|
||
p { | ||
margin-bottom: 15px; | ||
font-size: 16px; | ||
} | ||
|
||
.input-section label { | ||
display: block; | ||
margin: 10px 0 5px; | ||
font-size: 14px; | ||
color: #ccc; | ||
} | ||
|
||
input { | ||
padding: 10px; | ||
width: calc(100% - 20px); | ||
margin-bottom: 10px; | ||
border: none; | ||
border-radius: 5px; | ||
font-size: 16px; | ||
} | ||
|
||
.tooltip { | ||
font-size: 12px; | ||
color: #aaa; | ||
display: block; | ||
margin-bottom: 10px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
background-color: #84cef5; | ||
border: none; | ||
border-radius: 5px; | ||
font-size: 16px; | ||
color: white; | ||
cursor: pointer; | ||
margin: 5px; | ||
transition: transform 0.3s ease; | ||
} | ||
|
||
button:hover { | ||
transform: scale(1.1); | ||
background-color: #67b3e1; | ||
} | ||
|
||
#output { | ||
margin-top: 20px; | ||
} | ||
|
||
#presentValue { | ||
font-size: 18px; | ||
font-weight: bold; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
body { | ||
padding: 20px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters