--- id: 56bbb991ad1ed5201cd392cf title: Write Reusable JavaScript with Functions challengeType: 1 videoUrl: https://scrimba.com/c/cL6dqfy forumTopicId: 18378 localeTitle: Запись многоразового JavaScript с функциями --- ## Description
В JavaScript мы можем разделить наш код на многократно используемые функции, называемые функциями . Вот пример функции:
function functionName () {
console.log («Hello World»);
}
Вы можете вызвать или вызвать эту функцию, используя ее имя, за которым следуют скобки, например: functionName(); Каждый раз, когда функция вызывается, она выводит сообщение "Hello World" на консоль dev. Весь код между фигурными фигурными скобками будет выполняться каждый раз, когда вызывается функция.
## Instructions
  1. Создайте функцию, называемую reusableFunction которая печатает "Hi World" в dev-консоли.
  2. Вызовите функцию.
## Tests
```yml tests: - text: reusableFunction should be a function testString: assert(typeof reusableFunction === 'function'); - text: reusableFunction should output "Hi World" to the dev console testString: assert(hiWorldWasLogged); - text: Call reusableFunction after you define it testString: assert(/^\s*reusableFunction\(\)\s*/m.test(code)); ```
## Challenge Seed
```js // Example function ourReusableFunction() { console.log("Heyya, World"); } ourReusableFunction(); // Only change code below this line ```
### Before Tests
```js var logOutput = ""; var originalConsole = console; var nativeLog = console.log; var hiWorldWasLogged = false; function capture() { console.log = function (message) { if(message === 'Hi World') hiWorldWasLogged = true; 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 = nativeLog; } capture(); ```
### After Tests
```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(); ```