Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

73 lines
1.3 KiB
Markdown

---
id: 587d7b7e367417b2b2512b23
title: 使用 parseInt 函数
challengeType: 1
videoUrl: 'https://scrimba.com/c/cm83LSW'
forumTopicId: 301183
dashedName: use-the-parseint-function
---
# --description--
`parseInt()`函数解析一个字符串返回一个整数下面是一个示例:
`var a = parseInt("007");`
上面的函数把字符串 "007" 转换成数字 7。 如果字符串参数的第一个字符是字符串类型的,结果将不会转换成数字,而是返回`NaN`.
# --instructions--
`convertToInteger`函数中使用`parseInt()`将字符串`str`转换为正数并返回。
# --hints--
`convertToInteger`应该使用`parseInt()`函数。
```js
assert(/parseInt/g.test(code));
```
`convertToInteger("56")`应该返回一个数字。
```js
assert(typeof convertToInteger('56') === 'number');
```
`convertToInteger("56")`应该返回 56。
```js
assert(convertToInteger('56') === 56);
```
`convertToInteger("77")`应该返回 77。
```js
assert(convertToInteger('77') === 77);
```
`convertToInteger("JamesBond")`应该返回 NaN。
```js
assert.isNaN(convertToInteger('JamesBond'));
```
# --seed--
## --seed-contents--
```js
function convertToInteger(str) {
}
convertToInteger("56");
```
# --solutions--
```js
function convertToInteger(str) {
return parseInt(str);
}
```