<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Percentage Calculator</title>
<style>
body {
background-color: #F9F9F9;
display: flex; /* Center the content horizontally */
justify-content: center; /* Center the content horizontally */
align-items: center;
height: 100vh;
margin: 0;
}
.container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
border-radius: 5px;
}
.form-group {
text-align: center;
}
.form-group label {
display: block;
}
/* Center-align number input fields */
input[type="number"] {
text-align: center;
font-weight: bold; /* Add this line to make the inputs bold */
}
.center-button {
text-align: center;
}
button {
display: inline-block;
background-color: #007bff;
color: #fff;
border: none;
padding: 10px 20px;
margin-top: 10px;
border-radius: 5px;
cursor: pointer;
}
/* Red "Clear" button */
button.clear-button {
background-color: red;
}
.discount-group {
margin-top: 10px;
text-align: center; /* Center text within the discount-group */
}
#result {
text-align: center; /* Center-align the result text */
}
/* Make the "Discount Percentage:" label bold */
.bold-label {
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h3>Shopping Percentage Calculator</h3>
<div class="form-group">
<b><label for="originalPrice">Original Price:</label></b>
<input type="number" id="originalPrice" placeholder="Enter Original Price" step="0.01">
</div>
<div class="discount-group">
<label for="discount" class="bold-label">Discount Percentage:</label> <!-- Apply bold-label class to make it bold -->
<br>
<input type="number" id="discount" placeholder="Enter Discount Percentage" step="0.01">
</div>
<div class="center-button">
<button onclick="calculateDiscount()">Calculate</button>
<button class="clear-button" onclick="clearFields()">Clear</button> <!-- Add "Clear" button and clearFields() function -->
</div>
<p id="result"><strong></strong></p> <!-- Wrap result in a strong tag to make it bold -->
</div>
<script>
function calculateDiscount() {
const originalPrice = parseFloat(document.getElementById("originalPrice").value);
const discountPercentage = parseFloat(document.getElementById("discount").value);
if (!isNaN(originalPrice) && !isNaN(discountPercentage)) {
const discountedPrice = originalPrice - (originalPrice * (discountPercentage / 100));
const savings = originalPrice - discountedPrice;
document.getElementById("result").innerHTML = `<strong>Discounted Price: ₹${discountedPrice.toFixed(2)}<br>Savings: ₹${savings.toFixed(2)}</strong>`;
} else {
document.getElementById("result").innerHTML = "<strong>অনুগ্রহ করে আপনার হিসাবটি Enter করুন।</strong>";
}
}
function clearFields() {
document.getElementById("originalPrice").value = "";
document.getElementById("discount").value = "";
document.getElementById("result").innerHTML = "<strong></strong>";
}
</script>
</body>
</html>
Posts
vvv
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated