-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTime-Converter.js
53 lines (39 loc) · 1.44 KB
/
Time-Converter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//------Pour que le site soit securise------\\
if (window.location.protocol != "https:") {
window.location.protocol="https:";
}
//------Element html------\\
const dayInput = document.querySelector('#day-input');
const calculateButton = document.querySelector('#calculate-button');
const hours = document.querySelector('#hours');
const minutes = document.querySelector('#minutes');
const seconds = document.querySelector('#seconds');
//------Constantes------\\
const hoursPerDay = 24;
const minutesPerHour = 60;
const secondsPerMinute = 60;
//------Fonction de calcul------\\
function performCalculation() {
let days = dayInput.value;
let calcHours = days * hoursPerDay;
let calcMinutes = calcHours * minutesPerHour;
let calcSeconds = calcMinutes * secondsPerMinute;
hours.innerText = `${calcHours.toFixed()} hours`;
minutes.innerText = `${calcMinutes.toFixed()} minutes`;
seconds.innerText = `${calcSeconds.toFixed()} seconds`;
}
//------Evenement clic sur le bouton de calcul------\\
calculateButton.addEventListener('click', performCalculation);
//------Evenement touche entrer dnas l'input------\\
dayInput.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
performCalculation();
}
});
//------Nombre de caractere dans l'input------\\
function limitNumberLength(input, maxLength) {
if (input.value.length > maxLength) {
input.value = input.value.slice(0, maxLength);
}
}