Advertisement
Onesible

Untitled

Mar 30th, 2025
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let daysInput = document.getElementById('days-input');
  3.     let hoursInput = document.getElementById('hours-input');
  4.     let minutesInput = document.getElementById('minutes-input');
  5.     let secondsInput = document.getElementById('seconds-input');
  6.    
  7.     let daysBtn = document.getElementById('daysBtn');
  8.     let hoursBtn = document.getElementById('hoursBtn');
  9.     let minutesBtn = document.getElementById('minutesBtn');
  10.     let secondsBtn = document.getElementById('secondsBtn');
  11.    
  12.     daysBtn.addEventListener('click', convertFromDays);
  13.     hoursBtn.addEventListener('click', convertFromHours);
  14.     minutesBtn.addEventListener('click', convertFromMinutes);
  15.     secondsBtn.addEventListener('click', convertFromSeconds);
  16.    
  17.     function convertFromDays(e) {
  18.         e.preventDefault();
  19.         let inputDays = Number(daysInput.value);
  20.         hoursInput.value = (inputDays * 24).toFixed(2);
  21.         minutesInput.value = (inputDays * 1440).toFixed(2);
  22.         secondsInput.value = (inputDays * 86400).toFixed(2);
  23.     }
  24.    
  25.     function convertFromHours(e) {
  26.         e.preventDefault();
  27.         let inputHours = Number(hoursInput.value);
  28.         daysInput.value = (inputHours / 24).toFixed(2);
  29.         minutesInput.value = (inputHours * 60).toFixed(2);
  30.         secondsInput.value = (inputHours * 3600).toFixed(2);
  31.     }
  32.    
  33.     function convertFromMinutes(e) {
  34.         e.preventDefault();
  35.         let inputMinutes = Number(minutesInput.value);
  36.         daysInput.value = (inputMinutes / 1440).toFixed(2);
  37.         hoursInput.value = (inputMinutes / 60).toFixed(2);
  38.         secondsInput.value = (inputMinutes * 60).toFixed(2);
  39.     }
  40.    
  41.     function convertFromSeconds(e) {
  42.         e.preventDefault();
  43.         let inputSeconds = Number(secondsInput.value);
  44.         daysInput.value = (inputSeconds / 86400).toFixed(2);
  45.         hoursInput.value = (inputSeconds / 3600).toFixed(2);
  46.         minutesInput.value = (inputSeconds / 60).toFixed(2);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement