freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-an.../basic-javascript/use-the-parseint-function.r...

2.4 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
587d7b7e367417b2b2512b23 Use the parseInt Function 1 Используйте функцию parseInt

Description

Функция parseInt() анализирует строку и возвращает целое число. Вот пример: var a = parseInt("007"); Вышеупомянутая функция преобразует строку «007» в целое число 7. Если первый символ в строке не может быть преобразован в число, то он возвращает NaN .

Instructions

Используйте функцию parseInt() в функции convertToInteger чтобы она преобразует входную строку str в целое число и возвращает ее.

Tests

tests:
  - text: <code>convertToInteger</code> должен использовать функцию <code>parseInt()</code>
    testString: 'assert(/parseInt/g.test(code), "<code>convertToInteger</code> should use the <code>parseInt()</code> function");'
  - text: <code>convertToInteger(&quot;56&quot;)</code> должен возвращать число
    testString: 'assert(typeof(convertToInteger("56")) === "number", "<code>convertToInteger("56")</code> should return a number");'
  - text: <code>convertToInteger(&quot;56&quot;)</code> должен возвращать 56
    testString: 'assert(convertToInteger("56") === 56, "<code>convertToInteger("56")</code> should return 56");'
  - text: <code>convertToInteger(&quot;77&quot;)</code> должен возвращать 77
    testString: 'assert(convertToInteger("77") === 77, "<code>convertToInteger("77")</code> should return 77");'
  - text: <code>convertToInteger(&quot;JamesBond&quot;)</code> должен вернуть NaN
    testString: 'assert.isNaN(convertToInteger("JamesBond"), "<code>convertToInteger("JamesBond")</code> should return NaN");'

Challenge Seed

function convertToInteger(str) {

}

convertToInteger("56");

Solution

// solution required