2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: a7f4d8f2483413a6ce226cac
|
|
|
|
title: Roman Numeral Converter
|
|
|
|
isRequired: true
|
|
|
|
challengeType: 5
|
|
|
|
videoUrl: ''
|
|
|
|
localeTitle: 罗马数字转换器
|
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-06-30 01:51:26 -07:00
|
|
|
<section id="description">将给定数字转换为罗马数字。所有<a href="http://www.mathsisfun.com/roman-numerals.html" target="_blank">罗马数字</a>答案都应以大写字母提供。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。尝试配对程序。编写自己的代码。 </section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id="instructions">
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
|
|
|
- text: <code>convertToRoman(2)</code>应该返回“II”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(2), "II");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(3)</code>应该返回“III”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(3), "III");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(4)</code>应该返回“IV”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(4), "IV");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(5)</code>应该返回“V”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(5), "V");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(9)</code>应该返回“IX”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(9), "IX");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(12)</code>应返回“XII”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(12), "XII");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(16)</code>应返回“XVI”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(16), "XVI");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(29)</code>应该返回“XXIX”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(29), "XXIX");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(44)</code>应该返回“XLIV”。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(44), "XLIV");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(45)</code>应该返回“XLV”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(45), "XLV");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(68)</code>应返回“LXVIII”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(68), "LXVIII");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(83)</code>应返回“LXXXIII”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(83), "LXXXIII");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(97)</code>应该返回“XCVII”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(97), "XCVII");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(99)</code>应返回“XCIX”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(99), "XCIX");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(400)</code>应返回“CD”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(400), "CD");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(500)</code>应返回“D”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(500), "D");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(501)</code>应返回“DI”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(501), "DI");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(649)</code>应返回“DCXLIX”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(649), "DCXLIX");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(798)</code>应返回“DCCXCVIII”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(798), "DCCXCVIII");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(891)</code>应返回“DCCCXCI”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(891), "DCCCXCI");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(1000)</code>应该返回“M”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(1000), "M");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(1004)</code>应返回“MIV”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(1004), "MIV");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(1006)</code>应返回“MVI”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(1006), "MVI");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(1023)</code>应返回“MXXIII”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(1023), "MXXIII");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(2014)</code>应返回“MMXIV”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(2014), "MMXIV");
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: <code>convertToRoman(3999)</code>应返回“MMMCMXCIX”
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(convertToRoman(3999), "MMMCMXCIX");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function convertToRoman(num) {
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
convertToRoman(36);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
|
|
/section>
|