Skip to content

Commit

Permalink
Create profit_loss.html
Browse files Browse the repository at this point in the history
  • Loading branch information
meghaverma3110 authored Oct 23, 2023
1 parent d3be339 commit bef62ee
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions Add Your Code Hs/profit_loss.html
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>

0 comments on commit bef62ee

Please sign in to comment.