- Related Questions & Answers
- Check if right triangle possible from given area and hypotenuse in Python
- Area of Circumcircle of a Right Angled Triangle?
- How to Calculate the Area of a Triangle using Python?
- Area of Incircle of a Right Angled Triangle in C Program?
- Area of Circumcircle of a Right Angled Triangle in C Program?
- Maximum sum of a path in a Right Number Triangle in C++
- Find other two sides of a right angle triangle in C++
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle?
- Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle What is Equilateral Triangle in C?
- Program to calculate area of Circumcircle of an Equilateral Triangle
- Program to calculate area and perimeter of equilateral triangle
- Java Program to calculate the area of a triangle using Heron's Formula
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle in C?
- Find other two sides and angles of a right angle triangle in C++
- Determining rightness of a triangle – JavaScript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are required to write a JavaScript function that takes in two numbers. The first number represents the length of the base of a right triangle and the second is perpendicular. The function should then compute the length of the hypotenuse based on these values.

**For example −**

If base = 8, perpendicular = 6

Then the output should be 10

Following is the code −

const base = 8; const perpendicular = 6; const findHypotenuse = (base, perpendicular) => { const bSquare = base ** 2; const pSquare = perpendicular ** 2; const sum = bSquare + pSquare; const hypotenuse = Math.sqrt(sum); return hypotenuse; }; console.log(findHypotenuse(base, perpendicular)); console.log(findHypotenuse(34, 56));

Following is the output on console −

10 65.5133574166368

Advertisements