Conditional (Ternary) Operator (code)

Tell us what’s happening:
Code not passing

Your code so far


function checkEqual(a, b) {
  return (a = b ? true : false);
}

checkEqual(1, 2);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/use-the-conditional-ternary-operator

I console.log(checkEqual(1, 2)) and the result is “true” which ought to be “false”

what could be wrong with my code? I have check over again for any errors and couldnt find one

You’re essentially asking the computer if it’s possble to assign variable b to variable a, which it is, so it returns true. You want to use == or === to compare a to b.

oh! you are very right! thank you

A useful tip here: the expression a === b will evaluate to a boolean, so you don’t need a ternary expression here, just:

function checkEqual(a, b) {
  return a === b;
}

That’s true, but the tests want the ternary operator