File tree 4 files changed +52
-54
lines changed
4 files changed +52
-54
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 9
9
</ head >
10
10
< body >
11
11
< div class ="container ">
12
- < div class ="heading "> Temperature Convertor</ div >
13
- < div class ="box ">
12
+ < h1 class ="heading "> Temperature Convertor</ h1 >
13
+ < div class ="temp-container ">
14
14
< label for ="celsius "> Celsius:</ label >
15
15
< input
16
+ onchange ="computeTemp(event) "
16
17
type ="number "
17
18
name ="celsius "
18
19
id ="celsius "
19
20
placeholder ="Enter Temperature "
20
- class ="input_box "
21
- onchange ="computeTemp(event) "
21
+ class ="input "
22
22
/>
23
23
</ div >
24
- < div class ="box ">
24
+ < div class ="temp-container ">
25
25
< label for ="fahrenheit "> Fahrenheit:</ label >
26
26
< input
27
+ onchange ="computeTemp(event) "
27
28
type ="number "
28
29
name ="fahrenheit "
29
30
id ="fahrenheit "
30
31
placeholder ="Enter Temperature "
31
- class ="input_box "
32
- onchange ="computeTemp(event) "
32
+ class ="input "
33
33
/>
34
34
</ div >
35
- < div class ="box ">
35
+ < div class ="temp-container ">
36
36
< label for ="kelvin "> Kelvin:</ label >
37
37
< input
38
+ onchange ="computeTemp(event) "
38
39
type ="number "
39
40
name ="kelvin "
40
41
id ="kelvin "
41
42
placeholder ="Enter Temperature "
42
- class ="input_box "
43
- onchange ="computeTemp(event) "
43
+ class ="input "
44
44
/>
45
45
</ div >
46
46
</ div >
47
-
48
47
< script src ="index.js "> </ script >
49
48
</ body >
50
49
</ html >
Original file line number Diff line number Diff line change
1
+ const celsiusEl = document . getElementById ( "celsius" ) ;
2
+ const fahrenheitEl = document . getElementById ( "fahrenheit" ) ;
3
+ const kelvinEl = document . getElementById ( "kelvin" ) ;
4
+
5
+ function computeTemp ( event ) {
6
+ const currentValue = + event . target . value ;
7
+
8
+ switch ( event . target . name ) {
9
+ case "celsius" :
10
+ kelvinEl . value = ( currentValue + 273.32 ) . toFixed ( 2 ) ;
11
+ fahrenheitEl . value = ( currentValue * 1.8 + 32 ) . toFixed ( 2 ) ;
12
+ break ;
13
+ case "fahrenheit" :
14
+ celsiusEl . value = ( ( currentValue - 32 ) / 1.8 ) . toFixed ( 2 ) ;
15
+ kelvinEl . value = ( ( currentValue - 32 ) / 1.8 + 273.32 ) . toFixed ( 2 ) ;
16
+ break ;
17
+ case "kelvin" :
18
+ celsiusEl . value = ( currentValue - 273.32 ) . toFixed ( 2 ) ;
19
+ fahrenheitEl . value = ( ( currentValue - 273.32 ) * 1.8 + 32 ) . toFixed ( 2 ) ;
20
+ break ;
21
+ default :
22
+ break ;
23
+ }
24
+ }
Original file line number Diff line number Diff line change 6
6
justify-content : center;
7
7
align-items : center;
8
8
font-family : monospace;
9
- font-size : 1.25rem ;
10
9
color : darkcyan;
11
10
}
12
11
13
- .heading {
14
- height : 58px ;
15
- line-height : 58px ;
16
- width : 100% ;
17
- font-size : 2rem ;
18
- font-weight : bolder;
19
- text-align : center;
20
- border-radius : 10px ;
21
- padding : 0 15px ;
22
- margin-bottom : 28px ;
23
- }
24
12
.container {
13
+ background : rgba (255 , 255 , 255 , 0.3 );
14
+ padding : 20px ;
15
+ box-shadow : 0 4px 10px rgba (0 , 0 , 0 , 0.3 );
16
+ border-radius : 10px ;
25
17
width : 85% ;
26
18
max-width : 450px ;
27
19
min-width : 350px ;
28
- padding : 20px ;
29
20
display : flex;
30
21
flex-direction : column;
31
22
align-items : center;
32
- border-radius : 10px ;
33
- background : rgba (255 , 255 , 255 , 0.3 );
34
- box-shadow : 0 4px 10px rgba (0 , 0 , 0 , 0.3 );
35
23
}
36
- .box {
24
+
25
+ .heading {
26
+ font-size : 32px ;
27
+ }
28
+
29
+ .temp-container {
37
30
width : 100% ;
38
31
padding : 15px ;
39
32
font-weight : bold;
33
+ font-size : 18px ;
40
34
}
41
- .input_box {
42
- width : 14rem ;
35
+
36
+ .input {
37
+ width : 220px ;
43
38
font-family : monospace;
44
39
padding : 5px ;
45
40
float : right;
46
41
outline : none;
47
42
background : rgba (255 , 255 , 255 , 0.3 );
48
43
border-color : rgba (255 , 255 , 255 , 0.5 );
49
44
color : darkgreen;
50
- font-size : 1.25 rem ;
45
+ font-size : 18 px ;
51
46
}
52
47
53
- .input_box ::placeholder {
54
- color : darkgray;
48
+
49
+ .input ::placeholder {
50
+ color : darkgray;
55
51
}
You can’t perform that action at this time.
0 commit comments