Skip to content

Commit

Permalink
Updated files
Browse files Browse the repository at this point in the history
  • Loading branch information
jordles committed Jun 22, 2024
1 parent 7ad80c2 commit 0665f8d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Day 29/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ function parseData(){
}
function startTimer(time){
clearInterval(countdown);
console.log(time);
let seconds = parseTime(time);
console.log('time', time);
console.log(seconds);
/* console.log(seconds); */
const endTime = Date.now() + seconds * 1000; //because date.now returns in ms, we have to convert our seconds to ms

displayTimeLeft(seconds);
Expand Down Expand Up @@ -105,8 +101,25 @@ document.customForm.addEventListener('submit', function(e) {
function addButton(time){
const button = document.createElement('button');
button.setAttribute('data-time', time);
const timeParse = time.split(':').map(str => str.padStart(2, "0")).join(':');
button.textContent = timeParse;
const timeParts = time.split(":");

const timeParse = timeParts
.map((str, index) => {
return {value: str.padStart(2, "0"), index: index};
})

if(!time.includes(':')){ //default is mins
button.textContent = `${time} min(s)`;
}
else if(timeParse.filter(parts => parts.value !== '00').length == 1){
const filteredTime = timeParse.filter(parts => parts.value !== '00');
console.log('filteredTime', filteredTime);
const unit = ["hour(s)", "min(s)", "secs"][filteredTime[0].index];
button.textContent = `${filteredTime[0].value} ${unit}`;
}
else{
button.textContent = timeParse.map(parts => parts.value).join(":");
}
button.addEventListener('click', parseData);
document.querySelector('.selection').appendChild(button);
}
Expand Down

0 comments on commit 0665f8d

Please sign in to comment.