1. ๋ฌธ์ œ

๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๊ฐ€ ๊ฐ™์ด ์กด์žฌํ•˜๋Š” ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ๋ฐ›์•„ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.

์ž…๋ ฅ์˜ˆ์ œ | StuDY

์ถœ๋ ฅ์˜ˆ์ œ | sTUdy

 

 

2. ๋ฌธ์ œํ’€์ด

answer๋Š” ๋นˆ ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ค์–ด ๋†“๊ณ , ์ธ์ˆ˜๋กœ ๋ฐ›์€ ๋ฌธ์ž์—ด์„ for of๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ํ•˜๋‚˜์”ฉ ๋Œ๋ฉด์„œ if-else๋ฌธ์œผ๋กœ ๋Œ€๋ฌธ์ž์ด๋ฉด ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์„œ ๋ˆ„์ ํ•˜๊ณ , ์†Œ๋ฌธ์ž๋ฉด ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์„œ ๋ˆ„์ ํ•œ ๋’ค answer ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. 

function solution(str){
	for(let x of str){
		if(x === x.toUpperCase()){
    		answer += x.toLowerCase();
    	} else answer += x.toUpperCase();
    }
    return answer;
}

console.log(solution("StuDY"));

 

 

3. ์‚ฌ์šฉํ•œ ๊ฐœ๋…

- String.toUpperCase() 

๋ฌธ์ž์—ด์„ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜

- String.toLowerCase()

๋ฌธ์ž์—ด์„ ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜

+ Recent posts