How To Get Area Of The Triangle Using JavaScript

Related Code: Area of a Rectangle Related Code: Area of a Square In this article, we create a simple program and it’s called How To Get Area Of The Triangle Using JavaScript. How to run this program? It will ask the user to give the base or the width and the height of the triangle and our program will compute to get the area of the triangle. Formula to get the Area of a Triangle Base x Height JavaScript This script used to solve the base and the height of a triangle to get the area.
  1. <script>
  2. var base = parseInt(prompt("Type the width of a Triangle : "));
  3. var height = parseInt(prompt("Type the height of a Triangle : "));
  4. var solving_triangle = (base * height)/2;
  5.  
  6. document.write("<br>");
  7. document.write("<h2 style='color:blue; text-align:center;'>Area of Triangle</h2>");
  8. document.write("<b style='color:blue; font-size:18px;'> The <b style='color:red;'> Width</b> of Triangle is <b style='color:red;'>" + base + "</b>.</b></b><br /><br />");
  9. document.write("<b style='color:blue; font-size:18px;'> The <b style='color:red;'> Height</b> of Triangle is <b style='color:red;'>" + height + "</b>.</b></b><br /><br />");
  10. document.write("<b style='color:blue; font-size:18px;'> The <b style='color:red;'> Area</b> of Triangle is <b style='color:red;'>" + solving_triangle + "</b>.</b></b>");
  11. </script>

Output:

This is the given Base or Width. Base This is the given Height. HeightThis is the Result: ResultRelated Code: Area of a Rectangle Related Code: Area of a Square So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment