Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function attachEventsListeners() {
- let allBtns = document.querySelectorAll("input[type = button]");
- let days = document.getElementById("days");
- let hours = document.getElementById("hours");
- let minutes = document.getElementById("minutes");
- let seconds = document.getElementById("seconds");
- for (let bt of allBtns) {
- bt.addEventListener("click", onClick);
- }
- function onClick(event) {
- let funcsObj = {
- daysBtn: () => {
- let input = Number(days.value);
- hours.value = 24 * input;
- minutes.value = 24 * 60 * input;
- seconds.value = 24 * 3600 * input;
- },
- hoursBtn: () => {
- let input = Number(hours.value);
- days.value = input / 24;
- minutes.value = 60 * input;
- seconds.value = 3600 * input;
- },
- minutesBtn: () => {
- let input = Number(minutes.value);
- days.value = input / (24 * 60);
- hours.value = input / 60;
- seconds.value = 60 * input;
- },
- secondsBtn: () => {
- let input = Number(seconds.value);
- days.value = input / (24 * 3600);
- hours.value = input / 3600;
- minutes.value = input / 60;
- },
- };
- let elID = event.target.id;
- console.log(elID);
- funcsObj[elID]();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement