PROBLEM 35
Easy

Is the Last Digit Even?

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#35

Given non-negative `n`, print `YES` if its last digit is even, otherwise `NO`.

EXAMPLE

Example

Input
1234
Output
YES

LIMITS

Constraints

All numeric input values fit in JavaScript `Number`.
📖
LEARN Theory for this problem
+

### Is the Last Digit Even?

Integer division separates higher decimal/time units, while `%` returns the remainder. These two operations let a program isolate digits or split a total number of seconds/minutes into components.

💡
NEED HELP? Hints
+

['Decide which part comes from division and which part comes from the remainder.', 'Mentally substitute at least one value for each branch and verify that exactly the intended branch runs.']

ANSWER Solution
+
const fs = require('fs');

const n = Number(fs.readFileSync(0, 'utf8').trim());
const lastDigit = Math.abs(n) % 10;

console.log(lastDigit % 2 === 0 ? 'YES' : 'NO');