diff --git a/projects/tip-calculator/index.js b/projects/tip-calculator/index.js index 98cb079..69fff45 100644 --- a/projects/tip-calculator/index.js +++ b/projects/tip-calculator/index.js @@ -4,10 +4,17 @@ const tipInput = document.getElementById("tip"); const totalSpan = document.getElementById("total"); function calculateTotal() { - const billValue = billInput.value; - const tipValue = tipInput.value; + const billValue = Number(billInput.value); + const tipValue = Number(tipInput.value); const totalValue = billValue * (1 + tipValue / 100); totalSpan.innerText = totalValue.toFixed(2); } btnEl.addEventListener("click", calculateTotal); + +billInput.addEventListener("input", () => { + if (billInput.value < 0) billInput.value = 0; +}); +tipInput.addEventListener("input", () => { + if (tipInput.value < 0) tipInput.value = 0; +}); \ No newline at end of file