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
7 Answers
+ 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.
+ 2
It's 1/2(b*h)
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 )
0
Please help me with the javascript code
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>
0
D code is not working please help
0
@Temitope, what seems to be the problem?