-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
27 lines (18 loc) · 935 Bytes
/
script.js
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
function convertTemperature() {
const inputTemperature = parseFloat(document.getElementById("num").value);
const unit = document.getElementById("unit").value;
let convertedTemperature;
if (unit === "Celsius") {
// Temperature Conversion to Fahrenheit
convertedTemperature = (inputTemperature * 9/5) + 32;
document.getElementById("result").textContent = `${inputTemperature} degrees Celcius = ${convertedTemperature} degrees Fahrenheit.`;
}
else if (unit === 'Fahrenheit') {
// Temperature Conversion to Celsius
convertedTemperature = (inputTemperature - 32) * 5/9;
document.getElementById("result").textContent = `${inputTemperature} degrees Fahrenheit = ${convertedTemperature} degrees Celsius.`;
}
else {
document.getElementById("result").textContent = 'Please select a valid unit.';
}
}