Skip to content

#029 Buggy Code4

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

029 Buggy Code4

Emmy has written a function that returns a greeting to users.

However, she's in love with Mubashir, and would like to greet him slightly differently.

She added a special case in her function, but she made a mistake.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/029 Buggy Code4.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.

//Emmy has written a function that returns a greeting to users.
//However, she's in love with Mubashir, and would like to greet him slightly differently.
//She added a special case in her function, but she made a mistake.
function greeting(name) {
    if (name == "Mubashir") {
        return "Hello, my Love!";
    }
    else { return "Hello, " + name + "!"; }
}
import * as Test from '../testHelper.js';
Test.assertEquals(greeting("Matt"), "Hello, Matt!")
Test.assertEquals(greeting("Helen"), "Hello, Helen!")
Test.assertEquals(greeting("Mubashir"), "Hello, my Love!")

Clone this wiki locally