Skip to content

Instantly share code, notes, and snippets.

@edoves
Created March 20, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edoves/ffe9bd35a1e881e9f608a04f5872aa40 to your computer and use it in GitHub Desktop.
Save edoves/ffe9bd35a1e881e9f608a04f5872aa40 to your computer and use it in GitHub Desktop.
divisibleby3.
Hello; Hello World; World
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".
helloWorld(3) "Hello"
helloWorld(5) "World"
helloWorld(15) "Hello World"
// Answer
function helloWorld(num) {
if (num % 15 == 0) return "Hello World";
else if (num % 3 == 0) return "Hello";
else if (num % 5 == 0) return 'World';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment