-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOibsip_Task1_Temp_conv.html
95 lines (86 loc) · 2.54 KB
/
Oibsip_Task1_Temp_conv.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>Temperature Converter</title>
<style>
/* CSS styles for the temperature converter */
body {
font-family: Arial, sans-serif;
background-color: lightcyan;
}
#converter {
width: 400px;
margin: 0 auto;
background-color: floralwhite;
border-radius: 5px;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
h1 {
text-align: center;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="number"] {
width: 100%;
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
font-size: 16px;
margin-bottom: 20px;
}
button {
background-color: #4caf50;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #3e8e41;
}
#result {
font-size: 20px;
font-weight: bold;
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="converter">
<h1>Temperature Converter</h1>
<label>Celsius:</label>
<input type="number" id="celsius" placeholder="Enter temperature in Celsius" />
<label>Fahrenheit:</label>
<input type="number" id="fahrenheit" placeholder="Enter temperature in Fahrenheit" />
<button onclick="convert()">Convert</button>
<div id="result"></div>
</div>
<script>
function convert() {
// Get the input values
var celsius = document.getElementById("celsius").value;
var fahrenheit = document.getElementById("fahrenheit").value;
// Check which input was used
if (celsius != "") {
// Convert Celsius to Fahrenheit
var result = (celsius * 9) / 5 + 32;
document.getElementById("fahrenheit").value = result.toFixed(2);
} else if (fahrenheit != "") {
// Convert Fahrenheit to Celsius
var result = ((fahrenheit - 32) * 5) / 9;
document.getElementById("celsius").value = result.toFixed(2);
} else {
// Show an error message if no input was provided
document.getElementById("result").innerHTML = "Please enter a temperature to convert.";
}
}
</script>
</body>
</html>