- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

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

# Determining rightness of a triangle – JavaScript

We are required to write a JavaScript function that takes in three numbers say a, b and c representing the length of three sides of a triangle. The function should return true if those three sides represent a right-angle triangle, false otherwise.

## Right angle triangle

A triangle is a right-angle triangle if one of the three angles in the triangle is 90 degree. And one angle in the triangle is 90 degrees when the square of the longest side is equal to the sum of squares of the other two sides.

For example − 3, 4, 5, as

3*3 + 4*4 = 5*5 = 25

## Example

Following is the code −

const side1 = 8; const side2 = 10; const side3 = 6; const isRightTriangle = (a, b, c) => { const con1 = (a*a) === (b*b) + (c*c); const con2 = (b*b) === (a*a) + (c*c); const con3 = (c*c) === (a*a) + (b*b); return con1 || con2 || con3; }; console.log(isRightTriangle(side1, side2, side3));

## Output

Following is the output in the console −

true

- Related Questions & Answers
- Potier Triangle Method – Determining the Voltage Regulation of Alternators
- Determining a pangram string in JavaScript
- Determining isomorphic strings JavaScript
- Determining rank on basis of marks in JavaScript
- Determining full house in poker - JavaScript
- Determining happy numbers using recursion JavaScript
- Determining beautiful number string in JavaScript
- Determining sum of array as even or odd in JavaScript
- Calculate the hypotenuse of a right triangle in JavaScript
- Valid triangle edges - JavaScript
- Determining whether numbers form additive sequence in JavaScript
- WACC method in determining the value of a project
- How to print a triangle formed of '#' using JavaScript?
- Calculating the area of a triangle using its three sides in JavaScript
- Determining table or structure of an ABAP code

Advertisements