-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.js
73 lines (71 loc) · 2.57 KB
/
temp.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
70
71
72
73
var heat = document.getElementById('heat');
var fromscale = document.getElementById('fromscale');
var toscale = document.getElementById('toscale');
var result = document.getElementById('result');
var form = document.getElementById('temp');
form.addEventListener('submit', function(event){
if(!heat.value || !fromscale.value || !toscale.value)
{
alert("Please fill in all the fields");
}
else if(( fromscale.value === "f" || fromscale.value === "c" || fromscale.value === "k") && (toscale.value === "f" || toscale.value === "c" || toscale.value === "k"))
{
if(fromscale.value === "f" && toscale.value === "c" ){
var x = parseFloat(heat.value);
var y = 0.56*(x-32);
var z = toscale.value;
var u = z.toUpperCase();
result.innerText = "Result: " + y + " " + u;
event.preventDefault();
}
if(fromscale.value === "c" && toscale.value === "f"){
x = parseFloat(heat.value);
var y = 1.8*(x + 32);
var z = toscale.value;
var u = z.toUpperCase();
result.innerText = "Result: " + y + " " + u;
event.preventDefault();
}
if(fromscale.value === "c" && toscale.value === "k"){
x = parseFloat(heat.value);
var y = x + 273;
var z = toscale.value;
var u = z.toUpperCase();
result.innerText = "Result: " + y + " " + u;
event.preventDefault();
}
if(fromscale.value === "k" && toscale.value === "c"){
x = parseFloat(heat.value);
var y = x - 273;
var z = toscale.value;
var u = z.toUpperCase();
result.innerText = "Result: " + y + " " + u;
event.preventDefault();
}
if(fromscale.value === "f" && toscale.value === "k"){
x = parseFloat(heat.value);
var y = 0.56*(x - 32) + 273;
var z = toscale.value;
var u = z.toUpperCase();
result.innerText = "Result: " + y + " " + u;
event.preventDefault();
}
if(fromscale.value === "k" && toscale.value === "f"){
x = parseFloat(heat.value);
var y = 1.8*(x - 273) + 32;
var z = toscale.value;
var u = z.toUpperCase();
result.innerText = "Result: " + y + " " + u;
event.preventDefault();
}
if(fromscale.value === toscale.value)
{
var z = toscale.value;
var u = z.toUpperCase();
alert("Aise kaise challega didi. Conversion ki zaroorat hi nahi. Result " + heat.value + " " + u + " hi hoga.");
}
}
else{
alert("Are bhai bhai bhai bhai, input shai de do. Farenheit, Kelvin aur Celsius hi challega");
}
});