1
- let results = document . getElementById ( ' converted-value' )
1
+ let results = document . getElementById ( " converted-value" ) ;
2
2
3
3
// On change event for the second SELECT attribute
4
4
to . onchange = ( ) => {
5
- results . innerHTML = ""
6
- results . style . color = 'black'
7
-
8
- let from = document . getElementById ( 'from' )
9
- let to = document . getElementById ( 'to' )
10
- let input = document . getElementById ( 'input' ) . value
11
-
12
- let fromValue = from . value
13
- let toValue = to . value
14
-
15
- // Checking if both are same
16
- if ( fromValue === toValue ) {
17
- results . style . color = 'red'
18
- results . innerHTML = "CONVERSION UNITS SHOULD BE DIFFERENT!"
19
- }
20
-
21
- // Checking the input and passing it to appropriate functions
22
- if ( fromValue === 'celsius' && toValue === 'kelvin' ) {
23
- celsiusToKelvin ( input )
24
- }
25
-
26
- if ( fromValue === 'celsius' && toValue === 'fahrenheit' ) {
27
- celsiusToFahrenheit ( input )
28
- }
29
-
30
- if ( fromValue === 'fahrenheit' && toValue === 'kelvin' ) {
31
- fahrenheitToKelvin ( input )
32
- }
33
-
34
- if ( fromValue === 'fahrenheit' && toValue === 'celsius' ) {
35
- fahrenheitToCelsius ( input )
36
- }
37
-
38
- if ( fromValue === 'kelvin' && toValue === 'fahrenheit' ) {
39
- KelvinToFahrenheit ( input )
40
- }
41
-
42
- if ( fromValue === 'kelvin' && toValue === 'celsius' ) {
43
- KelvinToCelsius ( input )
44
- }
45
- }
5
+ results . innerHTML = "" ;
6
+ results . style . color = "black" ;
46
7
8
+ let from = document . getElementById ( "from" ) ;
9
+ let to = document . getElementById ( "to" ) ;
10
+ let input = parseInt ( document . getElementById ( "input" ) . value , 10 ) ;
11
+
12
+ let fromValue = from . value ;
13
+ let toValue = to . value ;
14
+
15
+ // Checking if both are same
16
+ if ( fromValue === toValue ) {
17
+ results . style . color = "red" ;
18
+ results . innerHTML = "CONVERSION UNITS SHOULD BE DIFFERENT!" ;
19
+ }
20
+
21
+ // Checking the input and passing it to appropriate functions
22
+ if ( fromValue === "celsius" && toValue === "kelvin" ) {
23
+ celsiusToKelvin ( input ) ;
24
+ }
25
+
26
+ if ( fromValue === "celsius" && toValue === "fahrenheit" ) {
27
+ celsiusToFahrenheit ( input ) ;
28
+ }
29
+
30
+ if ( fromValue === "fahrenheit" && toValue === "kelvin" ) {
31
+ fahrenheitToKelvin ( input ) ;
32
+ }
33
+
34
+ if ( fromValue === "fahrenheit" && toValue === "celsius" ) {
35
+ fahrenheitToCelsius ( input ) ;
36
+ }
37
+
38
+ if ( fromValue === "kelvin" && toValue === "fahrenheit" ) {
39
+ KelvinToFahrenheit ( input ) ;
40
+ }
41
+
42
+ if ( fromValue === "kelvin" && toValue === "celsius" ) {
43
+ KelvinToCelsius ( input ) ;
44
+ }
45
+ } ;
47
46
48
47
// Conversion of input values
48
+
49
49
const celsiusToKelvin = ( input ) => {
50
- results . innerHTML = `The final converted value is ${ parseInt ( input + 273.15 , 10 ) . toFixed ( 2 ) } `
51
- }
50
+ results . innerHTML = `The final converted value is ${ ( input + 273.15 ) . toFixed (
51
+ 2
52
+ ) } `;
53
+ } ;
52
54
53
55
const celsiusToFahrenheit = ( input ) => {
54
- results . innerHTML = `The final converted value is ${ parseInt ( input * ( 9 / 5 ) + 32 , 10 ) . toFixed ( 2 ) } `
55
- }
56
-
56
+ results . innerHTML = `The final converted value is ${ (
57
+ input * ( 9 / 5 ) +
58
+ 32
59
+ ) . toFixed ( 2 ) } `;
60
+ } ;
57
61
const fahrenheitToKelvin = ( input ) => {
58
- results . innerHTML = `The final converted value is ${ parseInt ( ( input + 459.67 ) * ( 5 / 9 ) , 10 ) . toFixed ( 2 ) } `
59
- }
62
+ results . innerHTML = `The final converted value is ${ (
63
+ ( input + 459.67 ) *
64
+ ( 5 / 9 )
65
+ ) . toFixed ( 2 ) } `;
66
+ } ;
60
67
61
68
const fahrenheitToCelsius = ( input ) => {
62
- results . innerHTML = `The final converted value is ${ parseInt ( ( input - 32 ) * ( 5 / 9 ) , 10 ) . toFixed ( 2 ) } `
63
- }
69
+ results . innerHTML = `The final converted value is ${ (
70
+ ( input - 32 ) *
71
+ ( 5 / 9 )
72
+ ) . toFixed ( 2 ) } `;
73
+ } ;
64
74
65
75
const KelvinToFahrenheit = ( input ) => {
66
- results . innerHTML = `The final converted value is ${ parseInt ( ( input * 1.8 ) - 459.67 , 10 ) . toFixed ( 2 ) } `
67
- }
76
+ results . innerHTML = `The final converted value is ${ (
77
+ input * 1.8 -
78
+ 459.67
79
+ ) . toFixed ( 2 ) } `;
80
+ } ;
68
81
69
82
const KelvinToCelsius = ( input ) => {
70
- results . innerHTML = `The final converted value is ${ parseInt ( input - 273.15 , 10 ) . toFixed ( 2 ) } `
71
- }
83
+ results . innerHTML = `The final converted value is ${ ( input - 273.15 ) . toFixed (
84
+ 2
85
+ ) } `;
86
+ } ;
0 commit comments