String case swap function - Javascript String Operation

Javascript examples for String Operation:String Case

Description

String case swap function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w w w .  j  a  v  a 2s . c  om*/
function swapCase(str) {
  var out = '';
  for (var i=0; i<str.length; i++) {
      if (str[i].toLowerCase() == str[i]) {
         out += str[i].toUpperCase();
      } else {
         out += str[i].toLowerCase();
      }
  }
  return out;
}
console.log(swapCase('Hello World This Is a TEST!'))
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials