-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
25 lines (21 loc) · 704 Bytes
/
script.js
File metadata and controls
25 lines (21 loc) · 704 Bytes
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
// 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"
}
}