Tip Calculator
// Function to calculate the tip and redirect to results page with a delay
function calculateTip(event) {
event.preventDefault(); // Prevent default link behavior
const billAmount = parseFloat(document.getElementById("bill").value);
const tipPercent = parseFloat(document.getElementById("tipPercent").value);
if (isNaN(billAmount) || billAmount <= 0) {
alert("Please enter a valid bill amount.");
return;
}
// Add a 2-second delay before submitting the form to allow vignette ad
setTimeout(() => {
document.getElementById("tipForm").submit();
}, 1000); // 2000 milliseconds = 2 seconds
}