-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.html
More file actions
44 lines (41 loc) · 1.52 KB
/
temp.html
File metadata and controls
44 lines (41 loc) · 1.52 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Temperature Converter</title>
<style>
body{
font-size:30px;
text-align:center;
background-color:lightblue;
}
</style>
</head>
<body>
<h1>Temperature Converter</h1>
<label for="temperature">Temperature:</label>
<input type="number" id="temperature" placeholder="Enter temperature">
<select id="unit">
<option value="celsius">Celsius</option>
<option value="fahrenheit">Fahrenheit</option>
</select>
<button onclick="convert()">Convert</button>
<p id="result"></p>
<script>
function convert() {
var temperature = parseFloat(document.getElementById("temperature").value);
var unit = document.getElementById("unit").value;
var resultElement = document.getElementById("result");
var convertedTemperature;
if (unit === "celsius") {
convertedTemperature = (temperature * 9/5) + 32;
resultElement.textContent = temperature + " Celsius is equal to " + convertedTemperature.toFixed(2) + " Fahrenheit.";
} else if (unit === "fahrenheit") {
convertedTemperature = (temperature - 32) * 5/9;
resultElement.textContent = temperature + " Fahrenheit is equal to " + convertedTemperature.toFixed(2) + " Celsius.";
}
}
</script>
</body>
</html>