-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTEMPERATURE CONVERSION PROGRAM JAVASCRIPT.txt
More file actions
112 lines (87 loc) · 2.36 KB
/
TEMPERATURE CONVERSION PROGRAM JAVASCRIPT.txt
File metadata and controls
112 lines (87 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
body{
font-family: Arial, sana-serif;
background-color: hsl(0, 0%, 95%);
}
h1{
color: hsl(223, 100%, 64%);
}
form{
background-color: hsl(0, 0%, 100%);
text-align: center;
max-width: 350px;
margin: auto;
padding: 25px;
border-radius: 10px;
box-shadow: 5px 5px 15px hsl(0, 0%, 0%, 0.3);
}
#textBox{
width: 50%;
font-size: 2em;
border: 2px solid hsl(0, 0%, 0%, 0.8);
border-radius: 4px;
margin-bottom: 15px;
}
label{
font-size: 1.5em;
font-weight: bold;
}
button{
margin-top: 15px;
background-color: hsl(0, 100%, 60%);
color: white;
font-size: 1.5em;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
}
button:hover{
background-color: hsl(0, 100%, 50%);
}
#result{
font-size: 1.75em;
font-weight: bold;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VINRADSRI</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form>
<h1>Temperature conversion:</h1>
<input type="number" id = "textBox" value = "0"><br>
<input type="radio" id="toFahrenheit" name="unit">
<label for="toFahrenheit">Celsius ➡️ Fahrenheit</label><br>
<input type="radio" id="toCelsius" name="unit">
<label for="toCelsius">Fahrenheit ➡️ Celsius</label><br>
<button type="button" onclick="convert()">submit</button>
<p id="result"></p>
</form>
<script src="index.js"></script>
</body>
</html>
// TEMPERATURE CONVERSION PROGRAM
const textBox = document.getElementById("textBox");
const toFahrenheit = document.getElementById("toFahrenheit");
const toCelsius = document.getElementById("toCelsius");
const result = document.getElementById("result");
let temp;
function convert(){
if(toFahrenheit.checked){
temp = Number(textBox.value);
temp = temp * 9 / 5 +32
result.textContent = temp.toFixed(1) + "°F";
}
else if(toCelsius.checked){
temp = Number(textBox.value);
temp = (temp - 32) * (5/9);
result.textContent = temp.toFixed(1) + "°C";
}
else{
result.textContent = "Select a unit";
}
}