PROBLEM 27
Easy

First Digit of a Three-Digit Number

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#27

Given a positive three-digit integer, print its first digit.

EXAMPLE

Example

Input
583
Output
5

LIMITS

Constraints

100 ≤ n ≤ 999
📖
LEARN Theory for this problem
+

### First Digit of a Three-Digit Number

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.', 'Separate input parsing, result computation, and output into distinct steps so errors are easier to spot.']

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

const text = fs.readFileSync(0, 'utf8').trim();
const firstDigit = Number(text[0]);

console.log(firstDigit);