Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Contains a Digit

Beyond the Courseeasy

Implement `hasDigit(s)` returning whether `s` contains at least one digit.

Sample tests

Input: hasDigit("abc1")
Output: true
Input: hasDigit("abc")
Output: false

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Anchoring the pattern would require the whole string to be a digit.

Learning resources

  • MDN: Regular expressions
Visualize this concept: Regular Expressions →
Approach & explanation (try first)

/\d/.test checks whether any digit appears anywhere in the string.

Loading...
⌘/Ctrl + Enter

Run your code to see results.