freeCodeCamp: Bug in Challenge: Use Multiple Conditional (Ternary) Operators.
Describe your problem and how to reproduce it: Bug - Test for below code fails with error: checkSign should use multiple conditional operators.
function checkSign(num) {
return (num!==0) ?(num>0) ? "positive"
: "negative"
: "zero";
}
console.log(checkSign(10));
console.log(checkSign(-10));
console.log(checkSign(0));
Screenshot -1:

Screenshot - 2:

How to reproduce It. Instead of Error: “checkSign should use multiple conditional operators.” Error should be: Using multiple ternary operators in statement-if-true part of ternary operator is not best practice.
(Increasing clarity of error message)
Add a Link to the page with the problem: Link to Challenge; Link to my post reporting bug on forum:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (11 by maintainers)
I would be for adding a note similar.
I agree that some tweaking makes sense. I’d would help if we can capture the fact that the test fails if a) you aren’t using a multiple ternary or b) the ternary isn’t in the expected format.
@FelixBoscoJ
Expected solution (one of 6, very similar to your final answer):
If-else version
A ternary, or multiple ternary, always can be written with if-else. The challenge and the description is accurate. We just want to add a clarifying comment or two to emphasize the best practice formatting for readability.