PROBLEM 8
Easy

Last Digit

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#8

Given a non-negative integer `n`, print its last digit.

EXAMPLE

Example

Input
4827
Output
7

LIMITS

Constraints

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

### Last Digit

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.', 'Before printing, output only the computed result and do not add explanatory text that is absent from the required format.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let n = Number(input);
let result = (((n) % (10)) + (10)) % (10);
console.log(result);