find the last digit of pi in javascript

To find the last digit of pi in JavaScript, we can use the Math object and the constant pi. We can then use the modulus operator % 10 to get the last digit of pi.

Here's the code:

index.tsx
const pi = Math.PI;
const lastDigitOfPi = pi % 10;

console.log(lastDigitOfPi); // Output: 1
93 chars
5 lines

In this code, we first assign the value of Math.PI to the pi constant. We then use the modulus operator % to get the remainder when pi is divided by 10, which gives us the last digit of pi.

Finally, we output the last digit of pi using console.log(). In this case, the output would be 1, since the last digit of pi is 1.

gistlibby LogSnag