대문자와 소문자가 같이 존재하는 문자열을 입력받아 대문자는 소문자로 소문자는 대문자로 변환하여 출력하는 프로그램을 작성하세요.
StuDY
sTUdy
<html>
<head>
<meta charset="UTF-8" />
<title>출력결과</title>
</head>
<body>
<script>
function solution(str) {
let answer = ""
for (let x of str) {
if (x === x.toUpperCase()) {
answer += x.toLowerCase()
}
if (x === x.toLowerCase()) {
answer += x.toUpperCase()
}
}
return answer
}
let str = "StuDy"
console.log(solution(str))
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<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>
</body>
</html>