Week 2 - REPLIT 조건문 09. isEitherEvenAndLessThan9

grl pwr·2022년 5월 3일
0

isEitherEvenAndLessThan9 함수를 작성하세요.

  • 함수의 인자로 숫자 두개가 주어졌을때 함수는 2가지 조건을 검사합니다.
  • 우선 두 숫자 중 적어도 하나가 짝수인지 확인합니다.
  • 그리고 두 숫자 모두 9보다 작은지를 확인합니다.
  • 두 조건을 모두 만족하는 경우만 true를 반환합니다.
let output = isEitherEvenAndLessThan9(2, 4);
console.log(output); // --> true

let output = isEitherEvenAndLessThan9(72, 2);
console.log(output); // --> false

문제풀이

function isEitherEvenAndLessThan9(num1, num2) {

  if ((num1 % 2 == 0 || num2 % 2 == 0) &&
    (num1 < 9 && num2 < 9)) {
   return true;
  } else {
    return false;
    }
}

let output = isEitherEvenAndLessThan9(2, 4);
let output2 = isEitherEvenAndLessThan9(72, 2);

console.log(output)
console.log(output2)

module.exports = { isEitherEvenAndLessThan9 }
  • if 다음에 ()을 주의해서 사용 그리고 if문 사용하면 else는 필수로 사용하기
  • 변수 이름으로 함수를 받고 받는 함수 안에 인자(argument) 꼭 적기
profile
4대륙 개발자

0개의 댓글