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); |
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 |