I made a script that changes the case, but result from using it on text is exactly the same text, without a single change. Can someone explain this?
var swapCase = function(letters){
    for(var i = 0; i<letters.length; i++){
        if(letters[i] === letters[i].toLowerCase()){
            letters[i] = letters[i].toUpperCase();
        }else {
            letters[i] = letters[i].toLowerCase();
        }
    }
   console.log(letters);
}
var text = 'So, today we have REALLY good day';
swapCase(text);
                You can use this simple solution.
var text = 'So, today we have REALLY good day';
var ans = text.split('').map(function(c){
  return c === c.toUpperCase()
  ? c.toLowerCase()
  : c.toUpperCase()
}).join('')
console.log(ans)
Using ES6
var text = 'So, today we have REALLY good day';
var ans = text.split('')
.map((c) =>
 c === c.toUpperCase() 
 ? c.toLowerCase()
 : c.toUpperCase()
).join('')
console.log(ans)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With