将摄氏温度转换为华氏度的Javascript程序
在此示例中,您将学习在JavaScript中将摄氏度值转换为华氏温度。
您可以使用以下公式将摄氏度值转换为华氏度:
fahrenheit = celsius * 1.8 + 32
例如:摄氏到华氏度
// program to convert celsius to fahrenheit // ask the celsius value to the user let celsius = prompt("Enter a celsius value: "); // calculate fahrenheit let fahrenheit = (celsius * 1.8) + 32 // display the result console.log(`${celsius} degree celsius is equal to ${fahrenheit} degree fahrenheit.`);
输出
Enter a celsius value: 55 55 degree celsius is equal to 131 degree fahrenheit.
在上述程序中,用户输入摄氏度值并存储在摄氏度变量中。然后,使用华氏公式将摄氏度值转换为华氏度。
您可以使用以下公式将华氏温度值转换为摄氏度:
celsius = (fahrenheit - 32) / 1.8
总计 0 评论