How to Find Area of Triangle When 3 Sides or Coordinates are Given in Javascript Full Project For Beginners

How to Find Area of Triangle When 3 Sides or Coordinates are Given in Javascript Full Project For Beginners

 

Welcome folks today in this blog post we will be building a program to calculate area of triangle when 3 sides or coordinates are given in javascript. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started create a index.html file and copy paste the code which is shown below

 

We will be taking all the 3 sides of triangle as input by the user

 

index.html

 

<!DOCTYPE html>
<html>
  <head>
    <title>Add Two Numbers in Javascript</title>
  </head>
  <body>
</body>
<script>
// JavaScript program to find the area of a triangle

const side1 = parseInt(prompt('Enter side1: '));
const side2 = parseInt(prompt('Enter side2: '));
const side3 = parseInt(prompt('Enter side3: '));

// calculate the semi-perimeter
const s = (side1 + side2 + side3) / 2;

//calculate the area
const areaValue = Math.sqrt(
  s * (s - side1) * (s - side2) * (s - side3)
);

console.log(
  `The area of the triangle is ${areaValue}`
);
</script>
</html>

 

See also  Notie.js Javascript Alert Toast Notification Library Full Tutorial with Examples

 

Now if you open index.html file inside the browser you will see the below result

 

 

Leave a Reply