초보 개발자의 일기
대소문자 변환 본문
728x90
문제
입력
- 첫 줄에 문자열이 입력된다. 문자열의 길이는 100을 넘지 않습니다.
출력
- 첫 줄에 대문자는 소문자로, 소문자는 대문자로 변환된 문자열을 출력합니다.
입력 예시
StuDY
출력 예시
sTUdy
풀이 방법
toUpperCase()와 toLowerCase()를 이용해 대소문자를 판별한 후
조건문을 써서 바꾸었다.
내 코드
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<script>
function solution(s){
let result="";
for(let x of s){
if(x===x.toUpperCase()) answer+=x.toLowerCase();
else answer+=x.toUpperCase();
}
return result;
}
console.log(solution("StuDY"));
</script>
</body>
</html>
Solution
<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>
느낀점
대 소문자 판별하는 법을 몰라 검색해 풀었다.
728x90