102 lines
2.4 KiB
Markdown
102 lines
2.4 KiB
Markdown
---
|
||
id: 587d8249367417b2b2512c41
|
||
title: 公制 - 英制转换器
|
||
challengeType: 4
|
||
videoUrl: ''
|
||
dashedName: metric-imperial-converter
|
||
---
|
||
|
||
# --description--
|
||
|
||
构建一个功能类似于此的完整堆栈JavaScript应用程序: <https://incongruous-beard.glitch.me/>。在这个项目上工作将涉及您在我们的入门项目上在Glitch上编写代码。完成此项目后,您可以将公共故障网址(到应用程序的主页)复制到此屏幕进行测试!您可以选择在另一个平台上编写项目,但必须公开显示我们的测试。使用[此链接](https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-project-metricimpconverter/)在Glitch上启动此项目或在GitHub上克隆[此存储库](https://github.com/freeCodeCamp/boilerplate-project-metricimpconverter/) !如果您使用Glitch,请记住将项目链接保存到安全的地方!
|
||
|
||
# --hints--
|
||
|
||
我将阻止客户端尝试猜测(嗅探)MIME类型。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
我会阻止跨站点脚本(XSS)攻击。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
我可以使用包含可接受的数字和单位的单个参数进行GET / api / convert并将其转换。 (提示:通过查找将标记单元开头的第一个字符的索引来拆分输入)
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
我可以将'gal'转换为'L',反之亦然。 (1加仑到3.78541升)
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
我可以将'lbs'转换为'kg',反之亦然。 (1磅至0.453592千克)
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
我可以将'mi'转换为'km',反之亦然。 (1英里到1.60934公里)
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
如果我的计量单位无效,则返回“无效单位”。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
如果我的号码无效,则返回“无效号码”。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
如果两者都无效,则返回“无效数字和单位”。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
我可以在我的参数中使用分数,小数或两者(即5,1 / 2,2.5 / 6),但如果没有提供,则默认为1。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
我的返回将包含initNum,initUnit,returnNum,returnUnit和字符串拼写单元,格式为“{initNum} {initial_Units}转换为{returnNum} {return_Units}”,结果舍入为字符串中的5位小数。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
所有16个单元测试都已完成并通过。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
所有5个功能测试都已完成并通过。
|
||
|
||
```js
|
||
|
||
```
|
||
|
||
# --solutions--
|
||
|
||
```js
|
||
/**
|
||
Backend challenges don't need solutions,
|
||
because they would need to be tested against a full working project.
|
||
Please check our contributing guidelines to learn more.
|
||
*/
|
||
```
|