JavaScript Program to Check if the Numbers Have Same Last Digit

To understand this example, you should have the knowledge of the following JavaScript programming topics:


Example: Check the Last Digit

Output

Enter a first integer: 8
Enter a second integer: 38
Enter a third integer: 88
8, 38 and 88 have the same last digit.

In the above example, the user is asked to enter three integers.

The three integer values are stored in variables a, b and c.

The last digit of an integer value is calculated using a modulus operator %.

% gives the remainder value. For example, 58 % 10 gives 8.

All the last digits are then compared using if..else statement and logical AND operator && operator.