Skip to content

Commit 255472a

Browse files
update temperature convertor project
1 parent f7ab3df commit 255472a

File tree

4 files changed

+52
-54
lines changed

4 files changed

+52
-54
lines changed

projects/temp-converter/index.js

-21
This file was deleted.

projects/temp-converter/index.html renamed to projects/temperature-convertor/index.html

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,41 @@
99
</head>
1010
<body>
1111
<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">
1414
<label for="celsius">Celsius:</label>
1515
<input
16+
onchange="computeTemp(event)"
1617
type="number"
1718
name="celsius"
1819
id="celsius"
1920
placeholder="Enter Temperature"
20-
class="input_box"
21-
onchange="computeTemp(event)"
21+
class="input"
2222
/>
2323
</div>
24-
<div class="box">
24+
<div class="temp-container">
2525
<label for="fahrenheit">Fahrenheit:</label>
2626
<input
27+
onchange="computeTemp(event)"
2728
type="number"
2829
name="fahrenheit"
2930
id="fahrenheit"
3031
placeholder="Enter Temperature"
31-
class="input_box"
32-
onchange="computeTemp(event)"
32+
class="input"
3333
/>
3434
</div>
35-
<div class="box">
35+
<div class="temp-container">
3636
<label for="kelvin">Kelvin:</label>
3737
<input
38+
onchange="computeTemp(event)"
3839
type="number"
3940
name="kelvin"
4041
id="kelvin"
4142
placeholder="Enter Temperature"
42-
class="input_box"
43-
onchange="computeTemp(event)"
43+
class="input"
4444
/>
4545
</div>
4646
</div>
47-
4847
<script src="index.js"></script>
4948
</body>
5049
</html>
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

projects/temp-converter/style.css renamed to projects/temperature-convertor/style.css

+18-22
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,46 @@ body {
66
justify-content: center;
77
align-items: center;
88
font-family: monospace;
9-
font-size: 1.25rem;
109
color: darkcyan;
1110
}
1211

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-
}
2412
.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;
2517
width: 85%;
2618
max-width: 450px;
2719
min-width: 350px;
28-
padding: 20px;
2920
display: flex;
3021
flex-direction: column;
3122
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);
3523
}
36-
.box {
24+
25+
.heading {
26+
font-size: 32px;
27+
}
28+
29+
.temp-container {
3730
width: 100%;
3831
padding: 15px;
3932
font-weight: bold;
33+
font-size: 18px;
4034
}
41-
.input_box {
42-
width: 14rem;
35+
36+
.input {
37+
width: 220px;
4338
font-family: monospace;
4439
padding: 5px;
4540
float: right;
4641
outline: none;
4742
background: rgba(255, 255, 255, 0.3);
4843
border-color: rgba(255, 255, 255, 0.5);
4944
color: darkgreen;
50-
font-size: 1.25rem;
45+
font-size: 18px;
5146
}
5247

53-
.input_box::placeholder {
54-
color: darkgray;
48+
49+
.input::placeholder{
50+
color: darkgray;
5551
}

0 commit comments

Comments
 (0)