Skip to content

#177 HelloHelloWorldWorld

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

177 HelloHelloWorldWorld

Write a function that takes an integer and:

If the number is a multiple of 3, return "Hello".

If the number is a multiple of 5, return "World".

If the number is a multiple of both 3 and 5, return "Hello World".

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/177 HelloHelloWorldWorld.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 takes an integer and:
//If the number is a multiple of 3, return "Hello".
//If the number is a multiple of 5, return "World".
//If the number is a multiple of both 3 and 5, return "Hello World".
function helloWorld(num) {
    if (num % 15 === 0) return "Hello World";
    if (num % 3 === 0) return "Hello";
    if (num % 5 === 0) return "World";
    return "";
}
import { assertEquals } from '../testHelper.js';
assertEquals(helloWorld(3), "Hello")
assertEquals(helloWorld(5), "World")
assertEquals(helloWorld(15), "Hello World")

Clone this wiki locally