title: how to interchange uppercase and lowercase letters in javascript?
body: <p>My program must change the case of my word on <strong>UpperCase</strong> or <strong>LowerCase</strong>.</p>
  <p><strong>Example:</strong></p>
  <p>word: &quot;cAPS&quot;</p>
  <p>solution: &quot;Caps&quot;</p>
  <p>All good, but.</p>
  <p>My program works well with one word.</p>
  <p>The program checks case of my word by two first symbols(Uppercase or Lower case) But when deal going to sentence I have a problem.</p>
  <p>I do not understand, how method I must use. Maybe need to use an array or cycle to doing this?</p>
  <p><strong>My problem:</strong></p>
  <p>word: &quot;wHY DO wE NEED cAPS lOCK?&quot;</p>
  <p>Code of my program:</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>let newWord = 'cAPS'
  word = newWord
  
  if (word.length &gt; 1) {
    var lengthWord = word.length
    if (word.substring(1) == word.toUpperCase().substring(1)) {
      newWord = word.toUpperCase(0, 1).substring(0, 1) +
        word.toLowerCase().substring(1)
      console.log(newWord)
    } else if (word.substring(0) == word.toUpperCase().substring(0)) {
      newWord = word.toLowerCase().substring(0)
      console.log(newWord)
    } else if (word.substring(0, 1) == word.toUpperCase().substring(0, 1)) {
      newWord = word
      console.log(newWord)
    }
  
  }</code></pre>
  </div>
  </div>
  </p>