Project Euler Problem 45 Solution

What is your hint or solution suggestion?
You can entirely bypass the triangular number part.
(this problem was solved entirely with math)

function triPentaHexa() {
  var pentaNum = 166
  while(true) {
    let pentaNum8 = 4*pentaNum*(3*pentaNum-1)
    if(Math.floor((pentaNum8+1)**.5)===(pentaNum8+1)**.5 && ((pentaNum8+1)**.5%4==3)) {
      return pentaNum8/8


Challenge: Problem 45: Triangular, pentagonal, and hexagonal

Link to the challenge:

Thank you for your solution suggestion.

Unfortunately, I will not be adding this solution at this time.

  1. You changed the function signature for triPentaHexa(num)

  2. You hard coded the starting value to 166

  3. Use of var should be avoided

  4. while(true) loops should be avoided

Oh, on that note, I have a question:
What’s the point of the input?

The idea is that the function finds the first triagonal/pentagonal/hexagonal number that is larger than the input.