From e19812c65cece12170f7b5894a6aab034bb2a140 Mon Sep 17 00:00:00 2001 From: RUSHILPATEL33 Date: Sat, 16 May 2026 12:47:01 +0530 Subject: [PATCH] fix: add validation for empty or whitespace-only tasks --- script.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index ca39a81..8c6f856 100644 --- a/script.js +++ b/script.js @@ -5,8 +5,17 @@ function addTask() { let input = document.getElementById("taskInput"); let taskText = input.value.trim(); - if (taskText === "") return; + if (taskText === "") { + input.style.border = "2px solid red"; + input.placeholder = "Task cannot be empty!"; + setTimeout(() => { + input.style.border = ""; + input.placeholder = "Enter your task"; + }, 2000); + return; + } + input.style.border = ""; tasks.push({ text: taskText, done: false }); input.value = ""; renderTasks(); @@ -66,14 +75,12 @@ function updateProgress() { `Progress: ${percent}% (${doneTasks}/${total} tasks completed)`; } - - // ⏱️ Timer let seconds = 0; let timer = null; function startTimer() { - if (timer !== null) return; // prevent multiple timers + if (timer !== null) return; timer = setInterval(() => { seconds++;