1.6 KiB

title
title
Use the Conditional (Ternary) Operator

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

Use the Conditional (Ternary) Operator

:checkered_flag: Problem Explanation:

  • You need to write a function named checkEqual, which checks if the two parameters are equal.
  • If the parameters are equal, Equal is to be returned else Not Equal should be returned.

:speech_balloon: Hint

Use ternary operator to check for equality.

try to solve the problem now

Spoiler Alert!

warning sign

Solution ahead!

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

Code Explanation:

  • A function checkEqual is declared, it accepts two parameters in variables a and b.
  • The return statement would return the value of the evaluated ternary expression.
  • The ternary expression checks if a and b are equal or not and returns Equal or Not Equal respectively.