Skip to content

Instantly share code, notes, and snippets.

@rvbsanjose
Last active August 29, 2015 13:59
Show Gist options
  • Save rvbsanjose/10708098 to your computer and use it in GitHub Desktop.
Save rvbsanjose/10708098 to your computer and use it in GitHub Desktop.
// Using the JavaScript language, have the function SwapCase(str) take the str parameter and swap the case of each character.
// For example: if str is "Hello World" the output should be hELLO wORLD. Let numbers and symbols stay the way they are.
// Input = "Hello-LOL" Output = "hELLO-lol"
// Input = "Sup DUDE!!?" Output = "sUP dude!!?"
function SwapCase( str ) {
var swap = '';
for ( var i = 0; i < str.length; i++ ) {
if ( str[i] == str[i].toUpperCase() )
swap += str[i].toLowerCase();
else
swap += str[i].toUpperCase();
}
return swap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment