Project Nayuki

Triangle solver (JavaScript)


Triangle diagram with sides and angles labelled
Variable Input Solution Solution 2
Area (square units):

Tips: In the triangle diagram, click on a letter to jump to that input. When solved, hover over a letter to read its value.


This JavaScript program calculates the missing sides and angles of a triangle. Give exactly 3 pieces of information, including at least one side.


  • All sides are measured in the same unit. For example, you cannot directly solve a triangle with the sides 3 metres, 5 feet, and 2 yards; you must convert the side lengths to a common unit first.

  • In a valid solution, all side lengths are positive, and all angles are greater than 0° and less than 180°.

  • 2 sides and an enclosed angle (SAS) always yields a unique solution.

  • 2 angles and a side (ASA, AAS) always yields a unique solution, provided that the two given angles add up to less than 180°.

  • 3 sides (SSS) yields a unique solution, or no solution if the longest side is longer than the sum of the other sides.

  • 2 sides and a non-enclosed angle (SSA) yields 0, 1, or 2 solutions.

The source code is available for viewing.


A standalone offline version is available for download: triangle-solver.html (right-click the link to save)

This file is free for personal use. For teachers or commercial use, please contact me to buy a registration for $10 USD.

More info