Basic JavaScript: Use the Conditional (Ternary) Operator question12345

Tell us what’s happening:
Can anybody help me with this task

Your code so far

function checkEqual(a, b) {
if(a === b) {
return "Equal"
else {
return "Not Equal"

checkEqual(1, 2);

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 9; LM-X420) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Mobile Safari/537.36.

Challenge: Use the Conditional (Ternary) Operator

Link to the challenge:


The code you currently have is using an if/else block. The challenge expects you to use a ternary operator instead.

The example the challenge provides is:

function findGreater(a, b) {
  return a > b ? "a is greater" : "b is greater";

But if you need some extra explanation of the syntax, I’ll provide another example:

return "this is a condition, like 0 === 0" ? "this part happens if the condition is true" : "or this part happens if the condition is false"
1 Like

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