If-Else, Switch-Case

목표


조건문 사용법을 이해한다.

If-else문


index.js의 내용을 전부 지운 뒤 다음 내용을 입력한다.

이후 Ctrl+S를 눌러 저장 후 콘솔창을 통해 정상적으로 출력되었는지 확인한다.

let a = 7;

if (a > 10) {
  console.log("a는 10보다 크다");
} else {
  console.log("a는 10보다 작거나 같다");
}

else if


let a = 7;

if (a > 10) {
  console.log("a는 10보다 크다");
} else if (a > 5) {
  console.log("a는 5보다 크고 10보다 작거나 같다");
} else {
  console.log("a는 5보다 작거나 같다");
}

Switch-case


let country = "ko";

switch (country) {
  case "ko":
    console.log("한국");
    break;
  case "jp":
    console.log("일본");
    break;
  case "us":
    console.log("미국");
    break;
  case "uk":
    console.log("영국");
    break;
  default:
    console.log("미분류");
}