JavaScript program to calculate square area and circumference

Views: 24   

Following program shows you how to calculate square area and circumference.
This program gets square length from user and calculates area and circumference and prints them using following formulas
Area = length X length
Circumference = 4 X length

var squareLength = parseInt(prompt("Enter length of square:"));
var areaOfSquare = squareLength * squareLength;
console.log("Area of square is: " + areaOfSquare);
var circumferenceOfSquare = 4 * squareLength;
console.log("Circumference of square is: " + circumferenceOfSquare);


Enter length of square:
Area of square is: 25.0
Circumference of square is: 20.0
On By