Triangle Type
Programming Basics · JavaScript
TASK
Problem
Given sides of a valid triangle, print `EQUILATERAL`, `ISOSCELES`, or `SCALENE`.
EXAMPLE
Example
5 5 8
ISOSCELES
LIMITS
Constraints
a, b, c > 0; triangle is valid
LEARN
Theory for this problem
+
### Triangle Type
`if / else if / else` chooses a branch from boolean conditions. Comparisons such as `<`, `>=`, `===` and logical operators `&&`, `||`, `!` combine the exact rules that decide which output is valid.
NEED HELP?
Hints
+
['Translate every case from the statement into a boolean condition before writing branches.', 'Check values exactly on the condition boundary: `=`, `<`, and `>` must match the statement without an off-by-one shift.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [a, b, c] = input.trim().split(/\s+/).filter(Boolean).map(Number);
if (((a) === (b)) && ((b) === (c))) {
console.log("EQUILATERAL");
} else {
if (((a) === (b)) || ((a) === (c)) || ((b) === (c))) {
console.log("ISOSCELES");
} else {
console.log("SCALENE");
}
}