w3resource logo


CoffeeScript exercises

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.

Solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

</body>
</html>

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

Live Demo :

JS Bin

Post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.