Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

JavaScript TEMPERATURE CONVERSION PROGRAM 🌡️

44.4K views on YouTube

#JavaScript #project #programming

00:00:00 HTML
00:04:20 CSS
00:10:43 JavaScript

// 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”;
}
}