[프로그래머스] 홀짝 구분하기

Chobby·2023년 4월 27일
1

Programmers

목록 보기
203/345

😀문제 설명

자연수 n이 입력으로 주어졌을 때 만약 n이 짝수이면 "n is even"을, 홀수이면 "n is odd."를 출력하는 코드를 작성해 보세요.


😁제한사항

  • 1 ≤ n ≤ 1,000

😂입출력 예

입력 #1

100

출력 #1

100 is even

입력 #2

1

출력 #2

1 is odd

🤣나의 풀이

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = line.split(' ');
}).on('close', function () {
    n = Number(input[0]);
    let preparedString = 'odd'
    if(n%2 === 0) {
        preparedString = 'even'
    }
    console.log(`${n} is ${preparedString}`)
});
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글