--- id: 56533eb9ac21ba0edf2244bd title: Passing Values to Functions with Arguments localeTitle: Pasando valores a funciones con argumentos challengeType: 1 --- ## Description
parámetros son variables que actúan como marcadores de posición para los valores que deben ingresarse en una función cuando se llama. Cuando se define una función, normalmente se define junto con uno o más parámetros. Los valores reales que se ingresan (o "pasan" ) en una función cuando se llama se conocen como argumentos . Aquí hay una función con dos parámetros, param1 y param2 :
function testFun(param1, param2) {
  console.log(param1, param2);
}
Entonces podemos llamar a testFun : testFun("Hello", "World"); Hemos pasado dos argumentos, "Hello" y "World" . Dentro de la función, param1 será igual a "Hello" y param2 será igual a "World". Tenga en cuenta que podría testFun llamar a testFun con diferentes argumentos y los parámetros tomarían el valor de los nuevos argumentos.
## Instructions
  1. Cree una función llamada functionWithArgs que acepte dos argumentos y envíe su suma a la consola dev.
  2. Llame a la función con dos números como argumentos.
## Tests
```yml tests: - text: functionWithArgs debería ser una función testString: 'assert(typeof functionWithArgs === "function", "functionWithArgs should be a function");' - text: ' functionWithArgs(1,2) debe generar 3 ' testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3, "functionWithArgs(1,2) should output 3");' - text: ' functionWithArgs(7,9) debe generar 16 ' testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16, "functionWithArgs(7,9) should output 16");' - text: Llame a functionWithArgs con dos números después de definirlo. testString: 'assert(/^\s*functionWithArgs\s*\(\s*\d+\s*,\s*\d+\s*\)\s*;/m.test(code), "Call functionWithArgs with two numbers after you define it.");' ```
## Challenge Seed
```js // Example function ourFunctionWithArgs(a, b) { console.log(a - b); } ourFunctionWithArgs(10, 5); // Outputs 5 // 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) 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 Test
```js console.info('after the test'); ```
## Solution
```js function functionWithArgs(a, b) { console.log(a + b); } functionWithArgs(10, 5); ```