From 1a3ded57782736d8077246c8b9deff2e2b3841da Mon Sep 17 00:00:00 2001 From: JohnWhite39 <124592559+JohnWhite39@users.noreply.github.com> Date: Tue, 16 Jul 2024 12:07:08 +0200 Subject: [PATCH] Update task.js --- js-features/countdown/task.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/js-features/countdown/task.js b/js-features/countdown/task.js index e69de29bb2..a1acaafe71 100644 --- a/js-features/countdown/task.js +++ b/js-features/countdown/task.js @@ -0,0 +1,16 @@ +const startingSeconds = parseInt(document.getElementById("timer").innerText); + +function updateTimer() { + let currentSeconds = parseInt(document.getElementById("timer").innerText); + + if (currentSeconds > 0) { + currentSeconds--; + document.getElementById("timer").innerText = currentSeconds; + + setTimeout(updateTimer, 1000); + } else { + alert("Вы победили в конкурсе!"); + } +} + +updateTimer();