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

Hi

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

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

checkEqual(1, 1);

THANKS IN ADVANCE!

1 Like

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);

1 Like

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

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

2 Likes

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

4 Likes

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.

1 Like

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

1 Like

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.

1 Like

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

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

checkEqual(1, 2);

Hi everyone! :innocent:

Be a little more careful.
The task states that you need to return “Equal” and “Not Equal”.
Therefore, the code will look like this:

function checkEqual(a, b)
{
return a === b ? “Equal” : “Not Equal” ;
}
checkEqual(1, 2);

1 Like

iam having the same problem how did you manage to get it right