Basic JavaScript: Use the Conditional (Ternary) Operator HELP ME

Basic JavaScript: Use the Conditional (Ternary) Operator HELP ME
0.0 0



I am struck here, please help. What is wrong with my code?

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

checkEqual(1, 1);



Your function does not return anything, so undefined gets returned by default.


Hi randell,
I have typed return in front of true and false, as well. I still don’t pass it.

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

checkEqual(1, 1);


Now you are not using the ternary operator as it is intended and creating an error.

You want to return the result of the ternary expression. Ternaries are not just another way to write an if statement which is what you are attempting to do with the last code you posted.

Think about how you would return a simple expression like a === b which would automatically evaluate to a true or false value.


I think I’m struck. I’ll refer to some videos on YT! Thanks randell!


The documentation for the ternary (conditional) operator gives great examples.


thanks man, I finally got it! :slight_smile:


I am stuck on this as well; my code looks like this

return (a === b) ? True : False;

I really don’t know what’s wrong here. How did you finally solve it?
Thanks for your help