Please help me find the area of a triangle where lengths of the three sides are 15.2cm, 12.1cm, and 14.7cm using JavaScript | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Please help me find the area of a triangle where lengths of the three sides are 15.2cm, 12.1cm, and 14.7cm using JavaScript

13th Nov 2016, 1:45 PM
Temitope
7 ответов
+ 2
Do you know the formula for the area of a triangle? If not, look it up. It'd be a great place to start.
13th Nov 2016, 2:48 PM
Keto Z
Keto Z - avatar
+ 2
It's 1/2(b*h)
13th Nov 2016, 3:59 PM
Keto Z
Keto Z - avatar
0
Yh. Let a,b,c be the lengths of the sides of a triangle. The area is given by: Area = √ p ( p − a ) ( p − b ) ( p − c )
13th Nov 2016, 3:57 PM
Temitope
0
Please help me with the javascript code
13th Nov 2016, 3:57 PM
Temitope
0
<html> <head> <title>Triangle's Area & Perimeter</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script type="text/javascript"> function Triangle(side1,side2,side3){ this.side1 = side1; this.side2 = side2; this.side3 = side3; this.getArea = function(){ return s = (this.side1 + this.side2 + this.side3)/2; area = squareRoot(s * (s-side1) * (s-side2) * (s-side3)); this.toString = function(){ return "The Triangle with sides = " + this.side1 + this.side2 + this.side3 + " has Area = " + this.getArea() + " ; }; } function calculate(){ var s = parseFloat(document.getElementById('side1','side2','side3').value); if(isNaN(s)){ document.getElementById('data').innerHTML = "Please enter numbers only"; return; } if(s<=0){ document.getElementById('data').innerHTML = "Negative numbers and Zero don't make sense"; return; } var myTriangle = new Triangle(); document.getElementById('data').innerHTML = myTriangle.toString(); } </script> </head> <body> <h3>Program Calculates Area</h3> <p>Enter the side1: <input type="text" id="side1" value="" /> <p>Enter the side2: <input type="text" id="side2" value="" /> <p>Enter the side3: <input type="text" id="side3" value="" /> <input type="button" value="Calculate" onClick="calculate()" /></p> <p id="data"></p> </body>
13th Nov 2016, 4:18 PM
Temitope
0
D code is not working please help
13th Nov 2016, 4:19 PM
Temitope
0
@Temitope, what seems to be the problem?
17th Nov 2016, 7:09 PM
Codde Ded
Codde Ded - avatar