Sunday, April 18, 2021

13. Write a JavaScript program to convert temperatures to and from celsius, fahrenheit

13. Write a JavaScript program to convert temperatures to and from celsius, fahrenheit.


function cToF(celsius) 
{
  var cTemp = celsius;
  var cToFahr = cTemp * 9 / 5 + 32;
  var message = cTemp+'\xB0C is ' + cToFahr + ' \xB0F.';
    console.log(message);
}

function fToC(fahrenheit) 
{
  var fTemp = fahrenheit;
  var fToCel = (fTemp - 32) * 5 / 9;
  var message = fTemp+'\xB0F is ' + fToCel + '\xB0C.';
    console.log(message);
cToF(60);
fToC(45);

No comments: