CoffeeScript: Find the area of a triangle

CoffeeScript: Exercise-4 with Solution

Write a CoffeeScript program to find the area of a triangle where lengths of the three of its sides are 5, 6, 7.

HTML Code :

<!DOCTYPE html>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
  <meta charset="utf-8">
  <title>Find the area of a triangle</title>


CoffeeScript Code :

side1 = 5
side2 = 6
side3 = 7
perimeter = (side1 + side2 + side3) / 2
area = Math.sqrt(perimeter * (perimeter - side1) * (perimeter - side2) * (perimeter - side3))
console.log area

Sample Output:


Live Demo :

See the Pen coffeescript-exercise-4 by w3resource (@w3resource) on CodePen.

Improve this sample solution and post your code through Disqus.

Follow us on Facebook and Twitter for latest update.