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>
<html>
<head>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
<meta charset="utf-8">
<title>Find the area of a triangle</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
Sample Output:
14.696938456699069
Live Demo :
See the Pen coffeescript-exercise-4 by w3resource (@w3resource) on CodePen.
Improve this sample solution and post your code through Disqus.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/coffeescript-exercises/coffeescript-exercise-4.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics