Invalid data in a challenge

In this challenge there is invalid example of conditional operator. There is:

function findGreater(a, b) { return a > b ? "a is greater" : "b is greater"; }

But in the “Get a Hint” section example has brackets in it, so the valid example is:
function findGreater(a, b) { return (a > b ? "a is greater" : "b is greater");.

Parentheses have two syntactic meaning in Javascript: to enclose parameters to a function, and to be a grouping operator (think PEMDAS, order of operations in arithmetic).

So, this is not an error. the return statement doesn’t take parameters, it returns the value of whatever expression is to the right of it:

1 Like

When i typed the answer, cosole didn’t pass my answer, cause there were no parentheses in it, but they were needed. I checked “Get a Hint” section, saw the parentheses in it and wrote them down, so i passed the challenge.

I’m not right. I didn’t pass it.

But now there is another mistake. There is not valid hint :smile:

Well, not passing the test but getting things logically correct can sometimes be a function of a logical error in the testing suite, and there is a place on the github for that. But before I’d launch an issue there, I’d ask to see your code between [SPOILER] code here [/SPOILER] tags.

But to show you that what I am saying is correct:

1 Like

Look at the example of conditional operator here:
and look at the hint here:

In the example they didn’t use parantheses, but in the hint they appear. There is another issue: if copy/paste solution in the hint, code doesn’t work. Check it by yourself.

The reason the solution doesn’t work is that it is erroneous for a different, common reason. The syntax of the return statement isn’t the problem. It’s that they are using the assignment operator, =, instead of the equality operator ==. Fix that, and you’ll see that it passes.

FYI, the assignment operator both assigns the value of the expression on the right to the variable on the left AND returns the value of the expression on the right, so in the return statement, as long as b isn’t 0 (a falsy value), the condition will always be true, so the checkEqual always returns true unless b == 0, which isn’t what we want.

So, congratulations on finding an error! Time to contribute, and gain the honor and esteem of your fellow coders! Open up an issue at the github:

1 Like


Thank you! :slight_smile:

1 Like