DEV Community

Cover image for Day 1: Arithmetic Operators Solution
Mohammad Hafijul Islam
Mohammad Hafijul Islam

Posted on

1

Day 1: Arithmetic Operators Solution

Task

Write two function for the following instructions:

  1. getArea(length, width): Calculate and return the area of a rectangle having sides length and width.
  2. getPerimeter(length, width): Calculate and return the perimeter of a rectangle having sides length and width.

The values returned by these functions are printed to stdout by locked stub code in the editor.

Constraints

  • 1 ≤ length, width ≤ 1000
  • length and width are scaled to at most three decimal places.

Input Format

getArea(length, width):

Data Type Parameter Description
Number length A number denoting the length of rectangle.
Number width A number denoting the width of rectangle.

getPerimeter(length, width):

Data Type Parameter Description
Number length A number denoting the length of rectangle.
Number width A number denoting the width of rectangle.

Output Format

Function Return Type Description
getArea(length, width) Number The area of a rectangle having sides length and width.
getPerimeter(length, width) Number The perimeter of a rectangle having sides length and width.

Sample

Input

3
4.5
Enter fullscreen mode Exit fullscreen mode

Output

13.5
15
Enter fullscreen mode Exit fullscreen mode

Explanation

  1. The area of the rectangle is length x width = 3 x 4.5 = 13.5.
  2. The perimeter of the rectangle is 2 x (length + width) = 2 x (3 + 4.5) = 15.

Solution

Arithmetic Operators

Connect

LinkedIn | GitHub

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more