title: Javascript - Transfer all letters in string into uppercase or lowercase
body: <p>I am a beginner in Javascript.<br />
  I tried to make a function about covert string into uppercase or lowercase.
  But I am confused why it can get expected output.
  Following is my function purpose and codes.Thank you!</p>
  <ol>
  <li>Function purpose :</li>
  </ol>
  <p>Ｗhen letter in string is uppercase, it will change into lowercase.
  When letter in string is lowercase, it will change into  uppercase.
  For example: &quot;Peter&quot; will transfer into &quot;pETER&quot;</p>
  <ol start="2">
  <li>Question:</li>
  </ol>
  <p>I can't understand why my code  ends up with &quot;Peter&quot; rather then &quot;pETER&quot;</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function swap(str) {
    var name = ''
    for (i = 0; i &lt;= str.length - 1; i++) {
      if (str[i] &gt;= 'a' &amp;&amp; str[i] &lt;= 'z') {
        str[i].toUpperCase()
      } else {
        str[i].toLowerCase()
      }
      name += str[i]
    }
    return name
  }
  
  console.log(swap('Peter'))</code></pre>
  </div>
  </div>
  </p>
  <p>I am not sure whether the problem is in this line.</p>
  <pre><code>if(str[i] &gt;= 'a' &amp;&amp; str[i] &lt;= 'z'){
    str[i].toUpperCase()
  }
  </code></pre>
  <p>Can anyone help me , thanks!!</p>