New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in Challenge: Use Multiple Conditional (Ternary) Operators. #38872
Comments
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. |
I do not think this is what the challenge asks for: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator This is the code from the docs:
What you have constructed is:
I agree, you have accomplished the task. However, the expected implemented logic is of the form:
So, perhaps we should change the challenge instructions to be more specific as to the format... |
Sir, please note: this repository is of Free Code Camp. Thank You for your reply. |
@FelixBoscoJ , haha. Yes, I am well aware. I linked to the Mozilla documentation to retrieve an example of Multiple Conditional Ternary Operators. My point is still entirely valid. |
function checkSign(num) {
return (num!==0) ?(num>0) ? "positive"
: "negative"
: "zero";
}
console.log(checkSign(10));
console.log(checkSign(-10));
console.log(checkSign(0)); Please try the above code in this challenge. Please check what is required to pass the challenge. |
@FelixBoscoJ , I have, and I understand exactly why this issue was created. I am pointing out that the format of your solution is not what is expected, which is clearly seen in the example given in the lesson:
I agree, you have accomplished the task. However, the expected implemented logic is of the form:
Your solution does not contain |
Sir the condition to win the challenge is: Use multiple conditional operators in the checkSign function to check if a number is positive, negative or zero. The function should return "positive", "negative" or "zero". We should Use Multiple Conditional (Ternary) Operators. |
Perhaps the error message should be "... multiple conditional operators in the recommended format." And perhaps adding a note along the lines of "It's is a best practice to format the multiple conditional operators so that each condition is on a separate line, as shown in the example, for readability." |
I would be for adding a note similar. |
Closed? Was an update to the description merged? |
@SKY020 It is not possible to implement if/else if/else logic using ternary Operator. But the task can be accomplished.
No, the expected implemented logic is of the form: function findGreaterOrEqual(a, b) {
if (a === b) {
return "a and b are equal";
}
else {
if (num>0) {
return "positive";
} else {
return "negative";
}
}
} |
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. |
Nevermind. |
It looks to me like adding clarifying comments is the best solution. So, let's leave this open until a PR gets merged. |
I'd like to jump on this, if possible. I'm a first-timer but really excited to learn! |
Go for it, @jasnkwcz. This should be a good issue for a first-timer. I recommend taking a look at the contribution guide, and if you get stuck ask away in the contributor's chat room |
Describe your problem and how to reproduce it:
Bug - Test for below code fails with error: checkSign should use multiple conditional operators.
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:
The text was updated successfully, but these errors were encountered: