freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../basic-algorithm-scripting/convert-celsius-to-fahrenheit/index.md

3.6 KiB
Raw Blame History

title localeTitle
Convert Celsius to Fahrenheit 将摄氏温度转换为华氏温度

:triangular_flag_on_post:如果卡住,请记得使用**Read-Search-Ask** 。尝试配对程序:busts_in_silhouette:并编写自己的代码:pencil:

:checkered_flag:问题说明:

从摄氏温度转换为华氏温度的算法是以摄氏度乘以9/5的温度加上32

您将获得一个可变摄氏度,表示摄氏温度。使用已定义的变量fahrenheit并应用算法为其分配相应的华氏温度。

相关链接

:speech_balloon:提示1

看看代码。有一个区域你不应该编辑。从那里开始,问问自己 - 我以前从未见过的那里使用了什么?

现在尝试解决问题

:speech_balloon:提示2

请记住**操作顺序,**请查看_链接_部分中的_链接_以获取更多信息。

现在尝试解决问题

扰流警报!

警告牌

提前解决!

:beginner:基本代码解决方案

    function convertToF(celsius) { 
      // Only change code below this line 
      var fahrenheit = (celsius * (9/5)) + 32; 
 
      // Only change code above this line 
      if ( typeof fahrenheit !== 'undefined' ) { 
      return fahrenheit; 
      } else { 
        return 'fahrenheit not defined'; 
      } 
    } 
 
    // Change the inputs below to test your code 
    convertToF(30); 

代码说明:

  • 声明fahrenheit变量。
  • 在需要时,确保使用括号( () )遵循正确的算术运算顺序。

:clipboard:捐款说明:

  • :warning: 请勿添加与任何现有解决方案类似的解决方案。如果您认为它**相似但更好** ,那么尝试合并(或替换)现有的类似解决方案。
  • 添加解决方案的说明。
  • 将解决方案分为以下类别之一 - 基本 中级高级:traffic_light:
  • 如果您添加了任何**相关的主要内容,**请仅添加您的用户名。 :warning: 不要 删除任何现有的用户名

看到:point_right: Wiki Challenge Solution Template供参考。