![]() |
A parallelogram is a geometric shape having four sides and its opposite sides are parallel and equal in length, and its opposite angles are also equal. We will use the formula area = base × height to return the area of a parallelogram in JavaScript. Formula Used// Formula for Area of Parallelogram Below are the approaches to Find the area of a Parallelogram: Table of Content Using FunctionIn this approach, Create a function that takes two input parameters one is the base of the parallelogram and the other is the height of the parallelogram. Inside the function, we will calculate the area using the formula for the area of a parallelogram: base × height. Call the function and return the calculated area. Example: The below example shows how to demonstrate finding the area of a parallelogram using the function.
Output Area of parallelogram is: 15 Time Complexity: O(1) Space Complexity: O(1) Using ClassWe will define a class named Parallelogram with a constructor method to initialize the base and height of the parallelogram, and we will define a method to calculate the area using the formula: base × height. Then we create an instance of the Parallelogram class and pass the base and height as arguments to the constructor. Call the method and print the result. Example: The below example shows how to demonstrate finding the area of a parallelogram using class.
Output Area of parallelogram is: 15 Time Complexity: O(1) Space Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |