Advertisement
viligen

timeConverter

Jun 1st, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function attachEventsListeners() {
  2.     let allBtns = document.querySelectorAll("input[type = button]");
  3.     let days = document.getElementById("days");
  4.     let hours = document.getElementById("hours");
  5.     let minutes = document.getElementById("minutes");
  6.     let seconds = document.getElementById("seconds");
  7.  
  8.     for (let bt of allBtns) {
  9.         bt.addEventListener("click", onClick);
  10.     }
  11.  
  12.     function onClick(event) {
  13.         let funcsObj = {
  14.             daysBtn: () => {
  15.                 let input = Number(days.value);
  16.                 hours.value = 24 * input;
  17.                 minutes.value = 24 * 60 * input;
  18.                 seconds.value = 24 * 3600 * input;
  19.             },
  20.             hoursBtn: () => {
  21.                 let input = Number(hours.value);
  22.                 days.value = input / 24;
  23.                 minutes.value = 60 * input;
  24.                 seconds.value = 3600 * input;
  25.             },
  26.             minutesBtn: () => {
  27.                 let input = Number(minutes.value);
  28.                 days.value = input / (24 * 60);
  29.                 hours.value = input / 60;
  30.                 seconds.value = 60 * input;
  31.             },
  32.             secondsBtn: () => {
  33.                 let input = Number(seconds.value);
  34.                 days.value = input / (24 * 3600);
  35.                 hours.value = input / 3600;
  36.                 minutes.value = input / 60;
  37.             },
  38.         };
  39.  
  40.         let elID = event.target.id;
  41.         console.log(elID);
  42.         funcsObj[elID]();
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement