Javascript Bytes (7): Comparing last digits

We make a function to find the last digit of two non-negative integers, and compare to see if the last two digits match. If they do, the function returns true, else, the function returns false.

function lastDigit(intOne, intTwo) {

//we needed to convert to string in order to use the slice method
//to find the last substring of our number
var lastDigitOne = intOne.toString().slice(-1);
var lastDigitTwo = intTwo.toString().slice(-1);

if (lastDigitOne === lastDigitTwo) {
return true;
} else {
return false;

lastDigit(22, 32);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s