← Back to challenges

What Type of Triangle?

JavaScriptHardconditionsmatharraysgeometry

Instructions

Create a function which returns the type of triangle, given the side lengths. Return the following values if they match the criteria.

  • No sides equal: "scalene"
  • Two sides equal: "isosceles"
  • All sides equal: "equilateral"
  • Less or more than 3 sides given: "not a triangle"

Examples

getTriangleType([2, 6, 5]) ➞ "scalene"

getTriangleType([4, 4, 7]) ➞ "isosceles"

getTriangleType([8, 8, 8]) ➞ "equilateral"

getTriangleType([3, 5, 5, 2]) ➞ "not a triangle"

Notes

  • You will be given an array of positive integers.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Making a Sandwich