TypeScript bootcamp · Lab 32

Count digits

easyStrings8 minLesson: Strings

Read the question, write TypeScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read a line; print how many digit characters it contains.

Input. One line.

Output. Count.

Examples

Example 1
Input
ab12c3
Output
3
Example 2
Input
hello
Output
0
Hint
  1. /[0-9]/g match length
Show correct code

Peek only after you have tried. You can still Check your own version.

const line = readLine();
console.log((line.match(/[0-9]/g) || []).length);
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.