logo image

JavaScript program to calculate triangle circumference

37


Following program shows you how to calculate triangle circumference. This program gets triangle sides from user and calculates circumference and prints it using following formula Circumference = side1 + side2 + side3

var triangleSide1 = parseInt(prompt("Enter the side1 of triangle:"));
var triangleSide2 = parseInt(prompt("Enter the side2 of triangle:"));
var triangleSide3 = parseInt(prompt("Enter the side3 of triangle:"));
var circumferenceOfTriangle = triangleSide1 + triangleSide2 + triangleSide3;
console.log("Circumference of triangle is: " + circumferenceOfTriangle);

Output:

Enter the side1 of triangle:
20
Enter the side2 of triangle:
10
Enter the side3 of triangle:
30
Circumference of triangle is: 60.0