You are here: Home / Topics / Write a program in JavaScript to find the Area of Triangle

Write a program in JavaScript to find the Area of Triangle

Filed under: JavaScript on 2023-08-06 20:41:33

Write a function that takes the base and height of a triangle and return its area.

Examples:

triArea(3, 2) ➞ 3

triArea(7, 4) ➞ 14

triArea(10, 10) ➞ 50

 

We will make a function triArea(base, height) which will take two values as parameters

Notes:

The area of a triangle is: (base * height) / 2

 

<script>

function triArea(base, height){

return (base * height) / 2;  //it is better to use parenthesis in complex calculations.

}

triArea(3, 2) //output 3

triArea(7, 4)  //output 14

triArea(10, 10)  //output 50

</script>


About Author:
M
Mr. Dubey     View Profile
Founder of MCQ Buddy. I just like to help others. This portal helps students in getting study material free. Share your stuff here so that others can get benefitted.