QQ截图20230722232207.jpg

【使用Codecademy学习Javascript】温度转换练习

代码

// today is 293 Kelvin
const kelvin = 293;
let celsius = kelvin - 273; //Kelvin to Celsius by subtracting 273 from the kelvin

//Fahrenheit = Celsius * (9/5) + 32
let fahrenheit = celsius * (9 / 5) + 32;

//round down the Fahrenheit temperature
fahrenheit = Math.floor(fahrenheit);
console.log(`The temperature is ${fahrenheit} degrees Fahreheit`);

输出

The temperature is 68 degrees Fahreheit

发表评论