- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing

- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM

- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers

- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources

# Calculate the hypotenuse of a right triangle in JavaScript

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

## Example

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));

## Output

Following is the output on console −

10 65.5133574166368

- Related Articles
- Given the “legs” of a right triangle, return its hypotenuse in Python
- Find the hypotenuse of a right angled triangle with given two sides in C++
- Show that in a right angled triangle, the hypotenuse is the longest side.
- In A Right Angled Triangle Base =12cm And Hypotenuse =15 CM Find The Perpendicular
- The length of the hypotenuse of an isosceles right-angled triangle is 24. Find the area of the triangle.
- Prove that the line segment joining the mid-point of the hypotenuse of a right triangle to its opposite vertex is half of the hypotenuse.
- Swift Program to find the hypotenuse of a right-angled triangle with sides l and b
- The length of the hypotenuse of an isosceles right-angled triangle is \( 20 . \) Find the perimeter and area of the triangle.
- Check if right triangle possible from given area and hypotenuse in Python
- Fill in the blanks to make the following statements true.In a right triangle, the hypotenuse is the ……. side.
- In a right-angled triangle with sides $a$ and $b$ and hypotenuse $c$, the altitude drawn on the hypotenuse is $x$. Prove that $ab\ =\ cx$."\n
- In a right - angled triangle, base is $12\ cm$ and hypotenuse is $15\ cm$. Find the Perpendicular.
- The two sides of a right-angled triangle are 6 cm and 8 cm. Find the length of the hypotenuse.
- If two sides of a right triangle are 3 cm and 7 cm. What is the length of the hypotenuse?
- Prove that in a right angle triangle, the square of the hypotenuse is equal the sum of squares of the other two sides.

Advertisements