Use the Conditional (Ternary) Operator

Tell us what’s happening:
The output of checkEqual(1, -1) should be false.
But when i test this in browser console, it’s true.
I dont get this point, i need help

Your code so far


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

checkEqual(1, -1);

Your browser information:

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

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

1 is greater than -1, so a>=b is true and your function returns true.

Hi @ArielLeslie .
Exactly.
But the expected output of this challenge is false and i dont know why

>=

is “greater than or equal to”, which is different from “equal to”, which is what the challenge is asking for.

The expected value is false because 1 is not equal to -1.

Then, why is this wrong?

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

checkEqual(2, 2);
5 Likes

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums


"true" is not the same as true. "false" is not the same as false. One is a string and just treated as text, the other is a boolean value.

4 Likes

Dont use “” around true or false.

here if you post full solution some" smart" guys will tell that you cannot post full solution he just wrapped in in “”
//solution
function checkEqual(a, b) {
return a == b ? true : false;
}

checkEqual(1, 2);

1 Like

thank you so much that explained a lot <3