Question: Triangle perimeter and area ( JavaScript ) A triangle's three vertices can be defined with three ( x , y ) coordinates. Ex: The figure

Triangle perimeter and area (JavaScript)
A triangle's three vertices can be defined with three (x, y) coordinates. Ex: The figure below shows a triangle with vertices (1,0),(2,4), and (4,3).
Write two functions: trianglePerimeter() and triangleArea(). Both functions have six integer parameters representing the coordinates of a triangle's three vertices.
The trianglePerimeter() function should calculate the length of each side using the distance formula below. Then the function should return the sum of the three sides' length.
Ex: The function call trianglePerimeter(1,0,2,4,4,3) returns 10.601814290236735, the sum of the three sides' length:
Distance from (1,0) to (2,4)=4.1231056256177
Distance from (2,4) to (4,3)=2.2360679774998
Distance from (4,3) to (1,0)=4.2426406871193
The triangleArea() function should calculate and return the triangle's area using the following equation:
x1(Y2-)+ x2(-1)+(Y1- Y2)|/2
Ex: The function call triangleArea(1,0,2,4,4,3) returns |1(4-3)+2(3-0)+4(0-4)|/2=|1+6+-16|/2=|-9|/2=4.5.
Hint: The JavaScript Math object has methods for squaring numbers, calculating a number's square root, and finding a number's absolute value.
Need to know what code to write the TODO area below
function trianglePerimeter(x1, y1, x2, y2, x3, y3){
// TODO: Write your code here
}
function triangleArea(x1, y1, x2, y2, x3, y3){
// TODO: Write your code here
}
console.log("Testing trianglePerimeter()...");
let perimeter = trianglePerimeter(1,0,2,4,4,3);
console.log("Perimeter ="+ perimeter);
console.log("Testing triangleArea()...");
let area = triangleArea(1,0,2,4,4,3);
console.log("Area ="+ area);
// Do NOT remove the following line:
export { trianglePerimeter, triangleArea };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!