// Pobranie elementów ze strony const etykieta = document.getElementById("etykieta"); const przyciskStart = document.getElementById("start"); const przyciskStop = document.getElementById("stop"); const przyciskReset = document.getElementById("reset"); // Zmienne pomocnicze let zegar = null; let sekundy = 0; // Funkcja formatująca czas do postaci GG:MM:SS function wyswietlCzas() { const g = Math.floor(sekundy / 3600); const m = Math.floor((sekundy % 3600) / 60); const s = sekundy % 60; const dwie = (liczba) => String(liczba).padStart(2, "0"); etykieta.textContent = dwie(g) + ":" + dwie(m) + ":" + dwie(s); } // START przyciskStart.addEventListener("click", function () { if (zegar === null) { zegar = setInterval(function () { sekundy++; wyswietlCzas(); }, 1000); przyciskStart.disabled = true; przyciskStop.disabled = false; } }); // STOP przyciskStop.addEventListener("click", function () { clearInterval(zegar); zegar = null; przyciskStart.disabled = false; przyciskStop.disabled = true; }); // RESET przyciskReset.addEventListener("click", function () { clearInterval(zegar); zegar = null; sekundy = 0; wyswietlCzas(); przyciskStart.disabled = false; przyciskStop.disabled = true; }); // Wyświetlenie początkowego czasu wyswietlCzas();