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

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



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


@morginador you’re so close. the challenge is asking for true, not True, and false, not False.


Hello, I’m having the same issue here is my code:
function checkEqual(a, b) {
return a === b ? “true” : “false”;

checkEqual(1, 2);


Hey @rayramez,
Create a new topic with your issue by using “Ask for help” button the challenge page.

As far as challenge is concerned,
See there is a difference between “true” and true in JavaScript.
Here, former is string and latter is Boolean.
Try solving now.


Thanks aditya_p, i found this out after I submited the question. Thanks


@rayramez, glad you found the answer.
However from now onwards, whenever you need help with any of the Freecodecamp challenges, use the “Ask For Help” button on your challenge page. It gives the link to the challenge as well as posts the code properly here on forum.


you did’nt use the return statement ,use the return statemnt then u got the answer !!!..


Weird I have the same code as you and passed all the tests.

  return a === b ? true : false;

checkEqual(1, 2);```

Wait I see you wrapped true and false in quotes. Take those quotes off and it should work for you as well. I am still new to this as well so don't quote me but I believe if I am correct wrapping true and false in quotes converts them into strings and therefore would not be a boolean anymore.


The solution for this in free code camp is wrong then. I copy and pasted it because even after watching videos I could not get this to work.

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

checkEqual(1, 2);

You have to insert a triple equals sign, instead of the single

Warning Solution Ahead…but not really lol


This code worked for me, thanks all

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


checkEqual(1, 2);


:white_check_mark: I agree! The “Get a hint” solution mistakenly used a single equal sign.


Do not use “” around true and false. Do it like - return a == b ? true: false;