← Back to challenges

AlTeRnAtInG cApS

JavaScriptHardconditionsformattingstrings

Instructions

Create a function that alternates the case of the letters in a string (known as Spongecase).

Examples

alternatingCaps("Hello") ➞ "HeLlO"

alternatingCaps("How are you?") ➞ "HoW aRe YoU?"

alternatingCaps("OMG this website is awesome!") ➞ "OmG tHiS wEbSiTe Is AwEsOmE!"

Notes

  • The first character should always be UPPERCASE.
  • Ignore spaces.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.