[Java Script] "짝수와 홀수"

soor.dev·2021년 2월 14일
0

Coding test

목록 보기
2/18
post-thumbnail

1. 문제 설명

정수 num이 짝수일 경우 Even을 반환, 홀수인 경우 Odd를 반환

2. 제한 조건

  • num은 int 범위의 정수
  • 0은 짝수

3. 입출력 예

4. 문제 해결

#1. if

#2. Ternary Operator

The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:), and finally the expression to execute if the condition is falsy. This operator is frequently used as a shortcut for the if statement.

condition ? value1 : value2;
console.log(name === "soor" ? "yes" : "no");
name === "soor"가 참이면 "yes", 그렇지 않으면 "no"를 출력

0개의 댓글