Ternary Operator Lesson is letting me pass when the code result is wrong?

Tell us what’s happening:
Describe your issue in detail here.
When I run this it should say “Not Equal” but it says “Equal” and the test still lets me pass as if the code is a success. Am I doing it wrong or is there a glitch?

  **Your code so far**

function checkEqual(a, b) {
return a === b ? "Equal" : "Not Equal";
}

checkEqual(1, 2);
console.log(checkEqual())
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36

Challenge: Use the Conditional (Ternary) Operator

Link to the challenge:

You are calling it twice. The first time:

checkEqual(1, 2);

They are not equal and it is returning “Not Equal” but you are not doing anything with that return value.

The second time:

console.log(checkEqual())

You are calling it with no values. So, in the function, a and b are undefined, so they are equal. It is returning “Equal” and you are logging it.

Try this:

console.log(checkEqual(1, 2))
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.