From 22e69efd6bc489fdb7280095c1c3d9313ae78fe9 Mon Sep 17 00:00:00 2001 From: Arnav-afk Date: Sun, 3 May 2026 09:13:52 +0530 Subject: [PATCH] Validate bill and tip values before calculation Add validation for bill and tip values in calculateTotal function --- projects/tip-calculator/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/projects/tip-calculator/index.js b/projects/tip-calculator/index.js index 98cb079..35facbb 100644 --- a/projects/tip-calculator/index.js +++ b/projects/tip-calculator/index.js @@ -6,8 +6,12 @@ const totalSpan = document.getElementById("total"); function calculateTotal() { const billValue = billInput.value; const tipValue = tipInput.value; + if(tipValue<=0||billValue<=0){ + alert("bill value or tip value cannot be less than equal to zero); + }else{ const totalValue = billValue * (1 + tipValue / 100); totalSpan.innerText = totalValue.toFixed(2); + } } btnEl.addEventListener("click", calculateTotal);