You are here: Home / Topics / Write a program to Find the Perimeter of a Rectangle in JavaScript

Write a program to Find the Perimeter of a Rectangle in JavaScript

Filed under: JavaScript on 2023-08-06 21:12:53

Create a function that takes length and width and finds the perimeter of a rectangle.
 

Examples

findPerimeter(6, 7) ➞ 26

findPerimeter(20, 10) ➞ 60

findPerimeter(2, 9) ➞ 22

 

Note: we will make a function findPerimeter which will take two parameters i.e height and width of rectangle. To calculate the perimeter of rectangle we will use formula

perimeter = 2 x height x width;

<script>

function findPerimeter(length, width){

var perimeter = 2 * length * width;

return perimeter;

}

var length = 23;

var height = 10;

//calculate the perimeter

var perimeter = findPerimeter(length, height);

console.log(perimeter); // this will print 460 in console.

</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.