--- id: 587d7b7e367417b2b2512b24 title: Use the Conditional (Ternary) Operator challengeType: 1 videoUrl: 'https://scrimba.com/c/c3JRmSg' --- ## Description <section id='description'> The <dfn>conditional operator</dfn>, also called the <dfn>ternary operator</dfn>, can be used as a one line if-else expression. The syntax is: <code>condition ? statement-if-true : statement-if-false;</code> The following function uses an if-else statement to check a condition: <blockquote>function findGreater(a, b) {<br> if(a > b) {<br> return "a is greater";<br> }<br> else {<br> return "b is greater";<br> }<br>}</blockquote> This can be re-written using the <code>conditional operator</code>: <blockquote>function findGreater(a, b) {<br> return a > b ? "a is greater" : "b is greater";<br>}</blockquote> </section> ## Instructions <section id='instructions'> Use the <code>conditional operator</code> in the <code>checkEqual</code> function to check if two numbers are equal or not. The function should return either "Equal" or "Not Equal". </section> ## Tests <section id='tests'> ```yml tests: - text: <code>checkEqual</code> should use the <code>conditional operator</code> testString: assert(/.+?\s*?\?\s*?.+?\s*?:\s*?.+?/.test(code), '<code>checkEqual</code> should use the <code>conditional operator</code>'); - text: <code>checkEqual(1, 2)</code> should return "Not Equal" testString: assert(checkEqual(1, 2) === "Not Equal", '<code>checkEqual(1, 2)</code> should return "Not Equal"'); - text: <code>checkEqual(1, 1)</code> should return "Equal" testString: assert(checkEqual(1, 1) === "Equal", '<code>checkEqual(1, 1)</code> should return "Equal"'); - text: <code>checkEqual(1, -1)</code> should return "Not Equal" testString: assert(checkEqual(1, -1) === "Not Equal", '<code>checkEqual(1, -1)</code> should return "Not Equal"'); ``` </section> ## Challenge Seed <section id='challengeSeed'> <div id='js-seed'> ```js function checkEqual(a, b) { } checkEqual(1, 2); ``` </div> </section> ## Solution <section id='solution'> ```js function checkEqual(a, b) { return a === b ? "Equal" : "Not Equal"; } ``` </section>