2021/12/17) 13. 大文字と小文字の変換


1.質問


<大文字と小文字の変換>
:大文字と小文字が同じ文字列を入力することで、ライタは大文字と小文字を大文字と小文字に変換して出力します.

2.解決方法


前に習った内容どおりにすればいいです.

3.正解

        <script>
            function solution(s){  
                let answer="";
                for(let x of s){
                    if(x===x.toUpperCase()) answer+=x.toLowerCase();
                    else answer+=x.toUpperCase();
                }
                return answer;
            }
            console.log(solution("StuDY"));
        </script>