Why does “str.charAt(i).toUpperCase()” not modify the string?
12:30 11 Mar 2015

I've been doing JavaScript exercises since i haven't been doing this for too long. Got most of them working but i've been staring blind at this one.

I need to make all lowercase upper & vice versa. I checked the solution and it was helpfull but i'm sure i can get my own code ( which is very different from the answer ) working as well.

Thanks for all bits of help.

function swapCase (str) {
  var sen = str;
  for ( var i = 0; i < sen.length; i++) {
    if (sen.charAt(i) === sen.charAt(i).toLowerCase()) {
      sen.charAt(i).toUpperCase();
    } else if (sen.charAt(i) === sen.charAt(i).toUpperCase()) {
      sen.charAt(i).toLowerCase();
    }
  } return sen;
}

console.log(swapCase("UPlowUPlow"));

P.s: I am aware that it's not the cleanest bit of code but i've been working on it for a while. :)

javascript