--- id: 56533eb9ac21ba0edf2244bd title: Passing Values to Functions with Arguments challengeType: 1 videoUrl: https://scrimba.com/c/cy8rahW forumTopicId: 18254 localeTitle: Передача значений в функции с аргументами --- ## Description
Параметры - это переменные, которые действуют как заполнители для значений, которые должны быть введены в функцию при ее вызове. Когда функция определена, она обычно определяется вместе с одним или несколькими параметрами. Фактические значения, которые вводятся (или «переданы» ) в функцию при ее вызове, называются аргументами . Вот функция с двумя параметрами param1 и param2 :
function testFun (param1, param2) {
console.log (param1, param2);
}
Затем мы можем вызвать testFun : testFun("Hello", "World"); Мы передали два аргумента: "Hello" и "World" . Внутри функции param1 будет равен «Hello», а param2 будет равен «World». Обратите внимание, что вы можете снова вызвать testFun с разными аргументами, и параметры будут принимать значение новых аргументов.
## Instructions
  1. Создайте функцию functionWithArgs которая принимает два аргумента и выводит их сумму в консоль dev.
  2. Вызовите функцию с двумя числами в качестве аргументов.
## Tests
```yml tests: - text: functionWithArgs should be a function testString: assert(typeof functionWithArgs === 'function'); - text: functionWithArgs(1,2) should output 3 testString: if(typeof functionWithArgs === "function") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3); - text: functionWithArgs(7,9) should output 16 testString: if(typeof functionWithArgs === "function") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16); - text: Call functionWithArgs with two numbers after you define it. testString: assert(/^\s*functionWithArgs\s*\(\s*\d+\s*,\s*\d+\s*\)\s*/m.test(code)); ```
## Challenge Seed
```js // Example function ourFunctionWithArgs(a, b) { console.log(a - b); } ourFunctionWithArgs(10, 5); // Outputs 5 // Only change code below this line. ```
### Before Tests
```js var logOutput = ""; var originalConsole = console function capture() { var nativeLog = console.log; console.log = function (message) { if(message) logOutput = JSON.stringify(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 Tests
```js uncapture(); if (typeof functionWithArgs !== "function") { (function() { return "functionWithArgs is not defined"; })(); } else { (function() { return logOutput || "console.log never called"; })(); } ```
## Solution
```js function functionWithArgs(a, b) { console.log(a + b); } functionWithArgs(10, 5); ```