- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Advertisements