-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
64 lines (52 loc) · 1.76 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
let isLoading = false;
let debt = 0;
const beginCalculation = ()=>{
if(isLoading || !debt) return;
document.querySelector('h2').style.opacity = 0;
let progress = 0;
const progressBar = document.querySelector('.progress-bar');
const loadingPhrases = document.getElementById('bsPhrases');
document.querySelector('button').classList.add('disabled');
isLoading = true;
const intervalId = setInterval(()=>{
if(progress%20 == 0)
{
loadingPhrases.innerText = loading_phrase();
}
if(progress >= 100){
clearInterval(intervalId);
setTimeout(()=>{
progressBar.setAttribute('aria-valuenow', 0);
progressBar.style.width = "0%";
},500);
completeLoading();
}
else{
progress += 1;
progressBar.setAttribute('aria-valuenow', progress);
progressBar.style.width = progress + "%";
}
}, 150);
};
const completeLoading = ()=>{
isLoading = false;
document.getElementById('bsPhrases').innerText = '';
document.querySelector('button').classList.remove('disabled');
document.querySelector('h2').style.opacity = 1;
document.getElementById('resultHours').innerText = calculateHours();
};
const calculateHours = () => {
return Math.round(((60000 + debt)/52) * (1/8.77) * .25);
};
document.querySelector('input').onkeyup = (e)=>{
if(e.keyCode === 13){
beginCalculation();
return;
}
debt = e.target.valueAsNumber;
if(debt)
document.querySelector('button').classList.remove('disabled');
else
document.querySelector('button').classList.add('disabled');
};
document.querySelector('button').onclick = beginCalculation;