--- id: 56533eb9ac21ba0edf2244bd title: Passing Values to Functions with Arguments challengeType: 1 videoUrl: '' localeTitle: 将值传递给带参数的函数 --- ## Description
参数是变量,它们作为调用函数时要输入到函数的值的占位符。定义函数时,通常将其与一个或多个参数一起定义。调用函数时输入(或“传递” )的实际值称为参数 。这是一个带有两个参数的函数, param1param2
function testFun(param1,param2){
console.log(param1,param2);
}
然后我们可以调用testFuntestFun("Hello", "World");我们通过了两个论点, "Hello""World" 。在函数内部, param1将等于“Hello”, param2将等于“World”。请注意,您可以使用不同的参数再次调用testFun ,并且参数将采用新参数的值。
## Instructions
  1. 创建一个名为functionWithArgs ,该函数接受两个参数并将其总和输出到开发控制台。
  2. 使用两个数字作为参数调用该函数。
## Tests
```yml tests: - text: functionWithArgs应该是一个函数 testString: 'assert(typeof functionWithArgs === "function", "functionWithArgs should be a function");' - text: 'functionWithArgs(1,2)应该输出3' testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3, "functionWithArgs(1,2) should output 3");' - text: 'functionWithArgs(7,9)应该输出16' testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16, "functionWithArgs(7,9) should output 16");' - text: 定义后,使用两个数字调用functionWithArgs 。 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 // solution required ```