← Back to challenges

Triangle and Parallelogram Area Finder

JavaScriptHardalgorithmsmathconditionsgeometry

Instructions

Write a function that accepts base (decimal), height (decimal) and shape ("triangle", "parallelogram") as input and calculates the area of that shape.

Examples

areaShape(2, 3, "triangle") ➞ 3

areaShape(8, 6, "parallelogram") ➞ 48

areaShape(2.9, 1.3, "parallelogram") ➞ 3.77

Notes

  • Area of a triangle is 0.5 * b * h
  • Area of a parallelogram is b * h
  • Assume triangle and parallelogram are the only inputs for shape.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Convert an Array to a String