In this post we are going to write a JavaScript program to find the “Area of Triangle”.
Here is the complete JavaScript program to find the “Area of Triangle”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Area of Traingle - Simple JavaScript Example</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Load Bootstrap library for better UI look & feel --> <link rel="stylesheet" type="text/css" media="screen" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" /> <script> function findAreaOfTriangle(){ var RecLen, RecWid, Area; RecLen = document.getElementById("rec_len").value; RecWid = document.getElementById("rec_wid").value; Area = RecLen * RecWid; document.getElementById("result").value = Area; } </script> </head> <body> <div class="container"> <br /> <h2>JavaScript to find Area of Square - Demo by Theonlytutorials.com</h2> <br /> <div class="form-group"> <label for="rec_len">Enter Rectangle Length:</label> <input type="text" class="form-control" id="rec_len" > </div> <div class="form-group"> <label for="rec_wid">Enter Rectangle Width:</label> <input type="text" class="form-control req" id="rec_wid" > </div> <div class="form-group"> <label for="result">Result:</label> <input type="text" class="form-control req" id="result" readonly > </div> <button type="submit" class="btn btn-default" onclick="findAreaOfTriangle()">Submit</button> </div> </body> </html> |
You can also see the demo of the above script here: