programming-examples/js/Array/Write a JavaScript program which accept a string as input and swap the case of each character. For example if you input 'The Quick Brown Fox' the output should be 'tHE qUICK bROWN fOX'..js
2019-11-15 12:59:38 +01:00

21 lines
481 B
JavaScript

str = 'c';
var UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var LOWER = 'abcdefghijklmnopqrstuvwxyz';
var result = [];
for(var x=0; x<str.length; x++)
{
if(UPPER.indexOf(str[x]) !== -1)
{
result.push(str[x].toLowerCase());
}
else if(LOWER.indexOf(str[x]) !== -1)
{
result.push(str[x].toUpperCase());
}
else
{
result.push(str[x]);
}
}
console.log(result.join(''));