-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
69 lines (53 loc) · 1.69 KB
/
script.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
65
66
67
68
69
console.log('Welcome to 🌡️ Temperature Converter');
const tempLoad = () => {
let fa = document.getElementById('fa');
fa.innerHTML = "";
fa.style.color = "#ffa41b";
setTimeout(() => {
fa.innerHTML = "";
fa.style.color = "#ffa41b";
}, 1000)
setTimeout(() => {
fa.innerHTML = "";
}, 2000)
setTimeout(() => {
fa.innerHTML = "";
}, 3000)
setTimeout(() => {
fa.innerHTML = "";
fa.style.color = "#ff5151";
}, 4000)
}
setInterval(() => {
fa.style.color = "#ffa41b";
tempLoad();
}, 5000);
tempLoad();
const calculateTemp = () => {
const numberTemp = document.getElementById('temp').value;
// console.log(numberTemp);
const tempSelected = document.querySelector('#temp_diff');
const valeTemp = temp_diff.options[tempSelected.selectedIndex].value;
// console.log(valeTemp);
// Convert temperature from Celcius to Fahrenheit
const celTOfah = (cel) => {
let fahrenheit = (cel * (9 / 5) + 32);
return fahrenheit;
}
// Convert temperature from Fahrenheit to Celsius
const fahTOcel = (fehr) => {
let celsius = ((fehr - 32) * 5 / 9);
return celsius;
}
let result;
if (valeTemp == "cel") {
result = celTOfah(numberTemp);
document.getElementById('resultContainer').innerHTML = `= ${result}°Fahrenheit`;
} else {
result = fahTOcel(numberTemp);
document.getElementById('resultContainer').innerHTML = `= ${result}°Celsius`;
}
setTimeout(() => {
window.location.reload();
}, 1500);
}