상세 컨텐츠

본문 제목

Switch 에 Default 추가

freeCodeCamp

by 반디날다 2023. 1. 9. 17:39

본문

Switch 에 Default 추가해서 표현하기

switch (num) {
  case value1:
    statement1;
    break;
  case value2:
    statement2;
    break;
...
  default:
    defaultStatement;
    break;
}

 

 

문제

Write a switch statement to set answer for the following conditions:
a - apple
b - bird
c - cat
default - stuff

 

 

답은

function switchOfStuff(val) {
  let answer = "";
  // Only change code below this line
  switch(val){
    case "a":
      answer ="apple";
      break;
    case "b":
      answer = "bird";
      break;
    case "c":
      answer = "cat";
      break;
    default:
      answer = "stuff";
      break;
  }


  // Only change code above this line
  return answer;
}

switchOfStuff(1);

'freeCodeCamp' 카테고리의 다른 글

Counting Cards  (1) 2023.01.16
동일한 옵션일 때의 Switch  (0) 2023.01.09
Switch  (0) 2023.01.09
Golf Code (if ~ else if)  (0) 2023.01.09
shift() & unshift()  (0) 2023.01.04

관련글 더보기