Pls any help, i'm stack under conditional (ternary) operator

Tell us what’s happening:
Describe your issue in detail here.

Your code so far


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

checkEqual(1, 2);

Your browser information:

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

Challenge: Use the Conditional (Ternary) Operator

Link to the challenge:

Hello @ahmedhudu21 ,

How will your code behave if I pass your function 5 and 6? How will your function know that it should test 5 and 6 and not 1 and 2?

Hi Slimattcode
By defining the function :slight_smile:

OK, but could this function check anything else than 1 and 2? And how would it do that, if it could?

I still don’t get it, a bit lost

OK, no worries. Let’s look at the function. What are the a, b variables in the function for? Why are they there? What do they do? And are you using them in the body of your function?

The a variable is the condition whiles the b variable is the code to run,
in this case i’m asked to check if the two variables (a, b) are equal or not using the conditional operator.
I tried using the if/else statement after struggling with the condiotional operator but all same, not passing the test.

The condiotional operator is not the problem. How is your code checking for a and b if they are not used inside your code? Now you have hard coded in 1 and 2, and that’s the only numbers your code can handle. How can you fix that?

Omg
i finally passed it , i realized i left out the main function given
Thanks a lot @Slimattcode

Happy to help. Good luck.

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