Skip to content

Commit

Permalink
Refactor code to use addLeadingZero function
Browse files Browse the repository at this point in the history
  • Loading branch information
Valik3201 committed Nov 22, 2023
1 parent 15b6884 commit 5cde287
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/js/02-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,12 @@ function updateCountdown() {

const { days, hours, minutes, seconds } = convertMs(timeDifference);

document.querySelector("[data-days]").textContent = days
.toString()
.padStart(2, "0");
document.querySelector("[data-hours]").textContent = hours
.toString()
.padStart(2, "0");
document.querySelector("[data-minutes]").textContent = minutes
.toString()
.padStart(2, "0");
document.querySelector("[data-seconds]").textContent = seconds
.toString()
.padStart(2, "0");
document.querySelector("[data-days]").textContent = addLeadingZero(days);
document.querySelector("[data-hours]").textContent = addLeadingZero(hours);
document.querySelector("[data-minutes]").textContent =
addLeadingZero(minutes);
document.querySelector("[data-seconds]").textContent =
addLeadingZero(seconds);
}

startBtn.addEventListener("click", function () {
Expand All @@ -144,3 +138,7 @@ resetBtn.addEventListener("click", function () {

endDate = null;
});

function addLeadingZero(value) {
return value.toString().padStart(2, "0");
}

0 comments on commit 5cde287

Please sign in to comment.