1.3 KiB
1.3 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
587d7b7e367417b2b2512b23 | 使用 parseInt 函數 | 1 | https://scrimba.com/c/cm83LSW | 301183 | use-the-parseint-function |
--description--
parseInt()
函數解析一個字符串返回一個整數。 下面是一個示例:
const a = parseInt("007");
上述函數將字符串 007
轉換爲整數 7
。 如果字符串中的第一個字符不能轉換爲數字,則返回 NaN
。
--instructions--
在 convertToInteger
函數中使用 parseInt()
將字符串 str
轉換爲一個整數,並返回這個值。
--hints--
convertToInteger
中應該使用 parseInt()
函數。
assert(/parseInt/g.test(code));
convertToInteger("56")
應該返回一個數字。
assert(typeof convertToInteger('56') === 'number');
convertToInteger("56")
應該返回 56。
assert(convertToInteger('56') === 56);
convertToInteger("77")
應該返回 77。
assert(convertToInteger('77') === 77);
convertToInteger("JamesBond")
應該返回 NaN
。
assert.isNaN(convertToInteger('JamesBond'));
--seed--
--seed-contents--
function convertToInteger(str) {
}
convertToInteger("56");
--solutions--
function convertToInteger(str) {
return parseInt(str);
}