2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 56533eb9ac21ba0edf2244b3
|
|
|
|
challengeType: 1
|
|
|
|
videoUrl: ''
|
|
|
|
localeTitle: 将摄氏温度转换为华氏温度
|
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2019-12-20 23:22:00 +08:00
|
|
|
<section id="description">从摄氏温度转换为华氏温度的算法是以摄氏度乘以<code>9/5</code>,再加上<code>32</code> 。您将获得一个参数<code>celsius</code>代表着摄氏温度。使用已准备好代表华氏温度的变量<code>fahrenheit</code>,将<code>celsius</code>摄氏温度变量值兑换成华氏温度值,然后存储在<code>farenheit</code>变量里。使用以上提到的算法将摄氏温度转换为华氏温度。不需要过多担心函数和返回语句,因为它们将会在未来的挑战中加以解释。目前,只需使用您已经学过的运算符。 </section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id="instructions">
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
|
|
|
- text: <code>convertToF(0)</code>应该返回一个数字
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(typeof convertToF(0) === 'number');
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToF(-30)</code>应该返回值<code>-22</code>
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(convertToF(-30) === -22);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToF(-10)</code>应该返回值<code>14</code>
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(convertToF(-10) === 14);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToF(0)</code>应返回值<code>32</code>
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(convertToF(0) === 32);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToF(20)</code>应返回值<code>68</code>
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(convertToF(20) === 68);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToF(30)</code>应返回值<code>86</code>
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(convertToF(30) === 86);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function convertToF(celsius) {
|
|
|
|
let fahrenheit;
|
|
|
|
return fahrenheit;
|
|
|
|
}
|
|
|
|
|
|
|
|
convertToF(30);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
```js
|
2019-12-20 23:22:00 +08:00
|
|
|
function convertToF(celsius) {
|
|
|
|
let fahrenheit = celsius * 9/5 + 32;
|
|
|
|
|
|
|
|
return fahrenheit;
|
|
|
|
}
|
|
|
|
|
|
|
|
convertToF(30);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
|
|
/section>
|