-
Notifications
You must be signed in to change notification settings - Fork 467
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
d3be339
commit bef62ee
Showing
1 changed file
with
66 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,66 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Profit and Loss Calculator</title> | ||
<style> | ||
.container { | ||
width: 300px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
|
||
input[type="number"] { | ||
width: 100%; | ||
padding: 5px; | ||
margin: 5px 0; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
padding: 10px; | ||
background-color: #007BFF; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2>Profit and Loss Calculator</h2> | ||
<label for="revenue">Total Revenue:</label> | ||
<input type="number" id="revenue" placeholder="Enter revenue" required> | ||
|
||
<label for="expenses">Total Expenses:</label> | ||
<input type="number" id="expenses" placeholder="Enter expenses" required> | ||
|
||
<button onclick="calculateProfitLoss()">Calculate</button> | ||
|
||
<div id="result"></div> | ||
</div> | ||
|
||
<script> | ||
function calculateProfitLoss() { | ||
const revenue = parseFloat(document.getElementById("revenue").value); | ||
const expenses = parseFloat(document.getElementById("expenses").value); | ||
|
||
if (isNaN(revenue) || isNaN(expenses)) { | ||
document.getElementById("result").innerHTML = "Please enter valid numbers."; | ||
} else { | ||
const profitLoss = revenue - expenses; | ||
let resultText = "Profit: $"; | ||
|
||
if (profitLoss < 0) { | ||
resultText = "Loss: $"; | ||
} | ||
|
||
resultText += Math.abs(profitLoss).toFixed(2); | ||
document.getElementById("result").innerHTML = resultText; | ||
} | ||
} | ||
</script> | ||
</body> | ||
</html> |