Skip to content

#127 Using Ternary Operators

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

127 Using Ternary Operators

Write a function that uses the ternary operator to return "yeah" if bool is true, and "nope" otherwise.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/127 Using Ternary Operators.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//Write a function that uses the ternary operator to return "yeah" if bool is true, and "nope" otherwise.
function yeah_nope(bool) {
    return bool ? "yeah" : "nope"
}
import { assertEquals } from '../testHelper.js';
assertEquals(yeah_nope(true), "yeah")
assertEquals(yeah_nope(false), "nope")

Clone this wiki locally