-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.html
More file actions
82 lines (73 loc) · 2.36 KB
/
task2.html
File metadata and controls
82 lines (73 loc) · 2.36 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
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
<!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>
* {
text-align: center;
}
body {
font-family: 'Arial', sans-serif;
margin: 50px;
background-image:url("task1.jpeg");
background-size:cover;
background-repeat:no repeat;
}
label {
margin-right: 10px;
}
input,
select,
button {
margin-bottom: 10px;
}
#result {
font-weight: bold;
}
</style>
</head>
<body>
<div id="temperature-container">
<h1>Temperature Converter</h1>
<table align="center">
<tr> <td><label for="temperature">Temperature in <sup>o</sup>C:</label></td>
<td> <input type="text" id="temperature" placeholder="Enter temperature" required></td></tr>
<tr><td> <label for="unit">Unit:</label></td>
<td> <select id="unit">
<option value="fahrenheit">Fahrenheit</option>
<option value="kelvin">Kelvin</option>
</select></td>
</tr></table>
<button onclick="convertTemperature()">Convert</button>
<div id="result"></div>
</div>
<script>
function convertTemperature() {
var temperatureInput = document.getElementById("temperature").value;
var unit = document.getElementById("unit").value;
if (isNaN(temperatureInput)) {
alert("Please enter a valid number for temperature.");
return;
}
var convertedTemperature;
switch (unit) {
case "celsius":
convertedTemperature = (parseFloat(temperatureInput) - 32) * 5/9;
break;
case "fahrenheit":
convertedTemperature = (parseFloat(temperatureInput) * 9/5) + 32;
break;
case "kelvin":
convertedTemperature = parseFloat(temperatureInput) + 273.15;
break;
default:
alert("Invalid unit.");
return;
}
document.getElementById("result").innerText = `Converted Temperature: ${convertedTemperature.toFixed(2)} ${unit.toUpperCase()}`;
}
</script>
</body>
</html>