- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

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

# Valid triangle edges - JavaScript

Suppose, we have three lines of length, respectively l, m and n. These three lines can only form a triangle, if the sum of any arbitrary two sides is greater than the third side.

For example, if the length of three lines is 4, 9 and 3, they cannot form a triangle because 4+3 is less than 9.

We are required to write a JavaScript function that the three numbers represents the length of three sides and checks whether they can form a triangle or not.

## Example

Following is the code −

const a = 9, b = 5, c = 3; const isValidTriangle = (a = 1, b = 1, c = 1) => { if(!a || !b || !c){ return false; }; const con1 = a + b > c; const con2 = b + c > a; const con3 = c + a > b; return con1 && con2 && con3; }; console.log(isValidTriangle(a, b, c));

## Output

Following is the output in the console −

false

- Related Articles
- Picking the triangle edges with maximum perimeter JavaScript
- Valid Triangle Number in C++
- Program to count number of valid triangle triplets in C++
- Check valid date format in JavaScript?
- Check for Valid hex code - JavaScript
- Finding the longest valid parentheses JavaScript
- Finding all valid word squares in JavaScript
- What characters are valid for JavaScript variable names?
- Is an empty iframe src valid in JavaScript?
- Check whether triangle is valid or not if sides are given in Python
- How to check whether a JavaScript date is valid?
- Check whether right angled triangle is valid or not for large sides in Python
- How To Check if a Triangle is Valid or Not When Sides are Given in Java?
- Edges and Vertices of Graph
- Checking if a number is a valid power of 4 in JavaScript

Advertisements