■ switch문을 사용하는 기본적인 방법을 보여준다.
▶ 예제 코드 (JAVASCRIPT)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
var month = 11; var monthName; switch(month) { case 1 : monthName = "January"; break; case 2 : monthName = "February"; break; case 3 : monthName = "March"; break; case 4 : monthName = "April"; break; case 5 : monthName = "May"; break; case 6 : monthName = "June"; break; case 7 : monthName = "July"; break; case 8 : monthName = "August"; break; case 9 : monthName = "September"; break; case 10 : monthName = "Novemver"; break; case 11 : monthName = "December"; break; default : mnothName = "Invalid month"; break; } console.log(monthName); |