Need help on this please: Use the Conditional (Ternary) Operator

The second condition is not returning ‘true’

Your code so far


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

}

checkEqual(1, 2);

Your browser information:

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

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

How would you solve this challenge using regular if else statement block? Can you write the logic to solve the challenge?

Yes i can do that with the if statement block

Can you post the code here of how you would do it?

if 1== 2 {
return false;
}
else if 1 == 1 {
return true;
}
else {
return false;
}

Why are you not using the parameters passed in to the function (a and b)? By the way, you wanna check if the 2 values are equal, if it is so you want to return true, not false. Plus you don’t need 2 conditions, one is enough.

Basically if a is equal to b return true, otherwise return false, that’s all the logic you need. Try to write that using regular if else block. Then proceed with ternary operator.

1 Like

Thanks a lot for your time…:relieved:
It was a great help
Sorry for the stress tho…:laughing: