-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.html
More file actions
54 lines (50 loc) · 1.84 KB
/
new.html
File metadata and controls
54 lines (50 loc) · 1.84 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Temperature Converter</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
.container {
max-width: 400px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container">
<h1>Temperature Converter</h1>
<p>Enter temperature:</p>
<input type="text" id="temperatureInput" placeholder="Enter Temperature" oninput="convertTemperature()">
<p>Convert to:</p>
<select id="unitSelector" onchange="convertTemperature()">
<option value="celsius">Celsius</option>
<option value="fahrenheit">Fahrenheit</option>
<option value="kelvin">Kelvin</option>
</select>
<p>Converted temperature:</p>
<p id="convertedTemperature">-</p>
</div>
<script>
function convertTemperature() {
var temperatureInput = parseFloat(document.getElementById("temperatureInput").value);
var unit = document.getElementById("unitSelector").value;
var convertedTemperature;
if (isNaN(temperatureInput)) {
document.getElementById("convertedTemperature").innerHTML = "Invalid input";
return;
}
if (unit === "celsius") {
convertedTemperature = temperatureInput;
} else if (unit === "fahrenheit") {
convertedTemperature = (temperatureInput * 9/5) + 32;
} else if (unit === "kelvin") {
convertedTemperature = temperatureInput + 273.15;
}
document.getElementById("convertedTemperature").innerHTML = convertedTemperature.toFixed(2) + " " + unit.toUpperCase();
}
</script>
</body>
</html>