--- id: 56bbb991ad1ed5201cd392cf title: Write Reusable JavaScript with Functions challengeType: 1 --- ## Description
In JavaScript, we can divide up our code into reusable parts called functions. Here's an example of a function:
function functionName() {
  console.log("Hello World");
}
You can call or invoke this function by using its name followed by parentheses, like this: functionName(); Each time the function is called it will print out the message "Hello World" on the dev console. All of the code between the curly braces will be executed every time the function is called.
## Instructions
  1. Create a function called reusableFunction which prints "Hi World" to the dev console.
  2. Call the function.
## Tests
```yml tests: - text: reusableFunction should be a function testString: assert(typeof reusableFunction === 'function', 'reusableFunction should be a function'); - text: reusableFunction should output "Hi World" to the dev console testString: assert("Hi World" === logOutput, 'reusableFunction should output "Hi World" to the dev console'); - text: Call reusableFunction after you define it testString: assert(/^\s*reusableFunction\(\)\s*;/m.test(code), 'Call reusableFunction after you define it'); ```
## Challenge Seed
```js // Example function ourReusableFunction() { console.log("Heyya, World"); } ourReusableFunction(); // Only change code below this line ```
### Before Test
```js var logOutput = ""; var originalConsole = console function capture() { var nativeLog = console.log; console.log = function (message) { if(message && message.trim) logOutput = message.trim(); if(nativeLog.apply) { nativeLog.apply(originalConsole, arguments); } else { var nativeMsg = Array.prototype.slice.apply(arguments).join(' '); nativeLog(nativeMsg); } }; } function uncapture() { console.log = originalConsole.log; } capture(); ```
### After Test
```js uncapture(); if (typeof reusableFunction !== "function") { (function() { return "reusableFunction is not defined"; })(); } else { (function() { return logOutput || "console.log never called"; })(); } ```
## Solution
```js function reusableFunction() { console.log("Hi World"); } reusableFunction(); ```