forked from surajagrawal01/Temperature-Conversion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (43 loc) · 1.42 KB
/
script.js
File metadata and controls
51 lines (43 loc) · 1.42 KB
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
const calctemp =()=>{
const temp1value = parseInt(document.getElementById("temp1value").value);
// console.log(temp1value);
const temp1Name = document.getElementById('temperature1');
const temp1type = temperature1.options[temp1Name.selectedIndex].value;
// console.log(temp1type);
const temp2Name = document.getElementById('temperature2');
// console.log(temp2Name);
const temp2type = temperature2.options[temp2Name.selectedIndex].value;
// console.log(temp2type);
if(temp1type === temp2type){
temp2value.value = temp1value;
console.log("Same");
}
else if(temp1type == "cel"){
if(temp2type == "farehn"){
temp2value.value = (( temp1value * 9/5) + 32).toFixed(2);
}
else if(temp2type == "kel"){
temp2value.value = (( temp1value + 273.15)).toFixed(2);
}
}
else if(temp1type == "farehn"){
if(temp2type == "cel"){
temp2value.value = ((temp1value - 32) * 5/9 ).toFixed(2);
}
else if(temp2type == "kel"){
temp2value.value = ((temp1value - 32) * 5/9 + 273.15 ).toFixed(2);
}
}
else if(temp1type == "kel"){
if(temp2type == "cel"){
temp2value.value = (temp1value- 273.15 ).toFixed(2);
}
else if(temp2type == "farehn"){
temp2value.value = ((temp1value - 273.15) * 9/5 + 32 ).toFixed(2);
}
}
}
let temp2value = document.getElementById('temp2value');
let result;
const btn = document.getElementById('convertBtn')
btn.addEventListener('click',calctemp)