/* styles.css */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 300px;
text-align: center;
}
h1 {
margin-bottom: 20px;
}
.input-group {
margin-bottom: 15px;
text-align: left;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
background-color: #28a745;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
width: 100%;
font-size: 16px;
}
button:hover {
background-color: #218838;
}
.result {
margin-top: 20px;
}
.result h2 {
margin-bottom: 10px;
}
.result p {
margin: 5px 0;
}
// script.js
document.getElementById('calculateBtn').addEventListener('click', function () {
// Get input values
const billAmount = parseFloat(document.getElementById('billAmount').value);
const tipPercentage = parseFloat(document.getElementById('tipPercentage').value);
const numPeople = parseInt(document.getElementById('numPeople').value);
// Validate inputs
if (isNaN(billAmount) || isNaN(tipPercentage) || isNaN(numPeople) || billAmount <= 0 || numPeople <= 0) {
alert('Please enter valid values for all fields.');
return;
}
// Calculate tip and total bill
const totalTip = (billAmount * tipPercentage) / 100;
const tipPerPerson = totalTip / numPeople;
const totalBill = billAmount + totalTip;
// Display results
document.getElementById('totalTip').textContent = totalTip.toFixed(2);
document.getElementById('tipPerPerson').textContent = tipPerPerson.toFixed(2);
document.getElementById('totalBill').textContent = totalBill.toFixed(2);
});