Skip to content

Commit

Permalink
added format function
Browse files Browse the repository at this point in the history
  • Loading branch information
JunZhao20 committed Nov 9, 2023
1 parent e3e9736 commit e0b2974
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion 12-Numbers-Dates-Timers-Bankist/starter/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,14 @@ if (ingredients.includes('spinach')) clearTimeout(pizzaTimer);
// console.log(time);
// }, 1000);

const formatTime = function (time) {
return time < 10 ? `0${time}` : time;
};

const clock = setInterval(() => {
const d = new Date();
const hour = d.getHours();
const min = d.getMinutes();
const sec = d.getSeconds();
console.log(`${hour}:${min}:${sec}`);
console.log(`${formatTime(hour)}:${formatTime(min)}:${formatTime(sec)}`);
}, 1000);

0 comments on commit e0b2974

Please sign in to comment.