Challenge 46

🔠🔡

ToGgLe CaSe

Open in Code Editor or Copy Instructions
...solutions at bottom of page...

Create a function that takes a string parameter and outputs the toggle/alternate case version of it

Examples:

toggleCase("I like to type like this") would return "I lIkE tO TyPe LiKe ThIS"

toggleCase("abcde") would return "AbCdE"

Extension:

Have the function take an additional parameter, which allows the user to specify whether the returned sequence should start with an uppercase or lowercase letter - i.e. if lowercase is chosen, the returned string would be aBcDe as opposed to AbCdE

Solutions

IGCSE 0478 / O-Level 2210 A-Level 9618