Today, we are going to write a function called
findPerimeter that will accept two integers,
width, as arguments.
You are given the length and the width of a rectangle. The goal of the function is to output the perimeter of that rectangle. I don’t know when in school you start learning simple geometry but you use this is how you calculate the perimeter of a rectangle:
perimeter = (length + width) * 2 perimeter = length + length + width + width perimeter = (length * 2) + (width * 2)
All of the examples above are the multiple ways you can get the perimeter of a rectangle. They’re all done differently but they all lead to the same answer.
Now that I helped you re-learn geometry, here are a couple of examples:
findPerimeter(6, 7) ➞ 26 findPerimeter(20, 10) ➞ 60
If you plug in those input values into the perimeter formulas above, your function will output the numbers following the arrow.
Here is a step by step process for the first example.
Length = 6 Width = 7 Perimeter = (6 + 7) * 2 Perimeter = (13) * 2 Perimeter = 26
Now that you understand this, let’s turn this into code.
It checks all the items of the Array, and whichever the first item meets, the condition is going to print. If more than one item meets the condition, then the first item satisfying the requirement is returned. Suppose that you want to find the first odd number in the Array. The argument function checks whether an argument passed to it is an odd number or not.
Does your business need an interactive website or app?
The technology used to develop the overall app by the developers from WebClues Infotech is at par with the latest available technology.
For more inquiry click here https://bit.ly/31eZyDZ
Book Free Interview: https://bit.ly/3dDShFg
With 15+ years of domain expertise, we have successfully delivered 13800+ projects and have successfully garnered 6800+ happy customers with 97%+ client retention rate.