← Back to challenges

Check String for Spaces

JavaScriptHardstringsvalidation

Instructions

Create a function that returns true if a string contains any spaces.

Examples

hasSpaces("hello") ➞ false

hasSpaces("hello, world") ➞ true

hasSpaces(" ") ➞ true

hasSpaces("") ➞ false

hasSpaces(",./!@#") ➞ false

Notes

  • An empty string does not contain any spaces.
  • Try doing this without RegEx.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Kinetic Energy