I'm asking for help

Tell us what’s happening:
I stuck in this subject(Use the Conditional (Ternary) Operator) because I do not know if I 've done wrong code .
please help me

Your code so far


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

}

var x1 = checkEqual(1, 2);
console.log(x1);


Your browser information:

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

Challenge: Use the Conditional (Ternary) Operator

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

Be careful with these strings:

" Equal" : " Not Equal";

They should not start with a space.

1 Like

Works fine more me. looks good. generally though you want to use ternaries sparingly.

regular if statements are preferable because they are easier to read at a glance

if (a === b):
    var x = ' Equal'
else: 
    var x =  ' Not Equal'
return x

or better yet

if (a !== b):
   return ' Not Equal'
return ' Equal'

can be understood quicker at a glance than

var x = (a === b) ? " Equal" : " Not Equal";
1 Like

But it’s only more readable because you have the ternary in one line.
If you move it into a more readable format, ternarys are easy to understand.

isLoggedIn
  ? "Hello"
  : "Please log in"
2 Likes