* 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>
73 lines
1.3 KiB
Markdown
73 lines
1.3 KiB
Markdown
---
|
|
id: 587d7b7e367417b2b2512b23
|
|
title: Use the parseInt Function
|
|
challengeType: 1
|
|
videoUrl: 'https://scrimba.com/c/cm83LSW'
|
|
forumTopicId: 301183
|
|
dashedName: use-the-parseint-function
|
|
---
|
|
|
|
# --description--
|
|
|
|
The `parseInt()` function parses a string and returns an integer. Here's an example:
|
|
|
|
`var a = parseInt("007");`
|
|
|
|
The above function converts the string "007" to an integer 7. If the first character in the string can't be converted into a number, then it returns `NaN`.
|
|
|
|
# --instructions--
|
|
|
|
Use `parseInt()` in the `convertToInteger` function so it converts the input string `str` into an integer, and returns it.
|
|
|
|
# --hints--
|
|
|
|
`convertToInteger` should use the `parseInt()` function
|
|
|
|
```js
|
|
assert(/parseInt/g.test(code));
|
|
```
|
|
|
|
`convertToInteger("56")` should return a number
|
|
|
|
```js
|
|
assert(typeof convertToInteger('56') === 'number');
|
|
```
|
|
|
|
`convertToInteger("56")` should return 56
|
|
|
|
```js
|
|
assert(convertToInteger('56') === 56);
|
|
```
|
|
|
|
`convertToInteger("77")` should return 77
|
|
|
|
```js
|
|
assert(convertToInteger('77') === 77);
|
|
```
|
|
|
|
`convertToInteger("JamesBond")` should return NaN
|
|
|
|
```js
|
|
assert.isNaN(convertToInteger('JamesBond'));
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```js
|
|
function convertToInteger(str) {
|
|
|
|
}
|
|
|
|
convertToInteger("56");
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```js
|
|
function convertToInteger(str) {
|
|
return parseInt(str);
|
|
}
|
|
```
|