3.3 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.3 KiB
		
	
	
	
	
	
	
	
id, title, challengeType, videoUrl, localeTitle
| id | title | challengeType | videoUrl | localeTitle | 
|---|---|---|---|---|
| 56533eb9ac21ba0edf2244bd | Passing Values to Functions with Arguments | 1 | 将值传递给带参数的函数 | 
Description
param1和param2 : function testFun(param1,param2){然后我们可以调用
console.log(param1,param2);
}
testFun : testFun("Hello", "World");我们通过了两个论点, "Hello"和"World" 。在函数内部, param1将等于“Hello”, param2将等于“World”。请注意,您可以使用不同的参数再次调用testFun ,并且参数将采用新参数的值。 Instructions
- 创建一个名为functionWithArgs,该函数接受两个参数并将其总和输出到开发控制台。
- 使用两个数字作为参数调用该函数。
Tests
tests:
  - text: <code>functionWithArgs</code>应该是一个函数
    testString: 'assert(typeof functionWithArgs === "function", "<code>functionWithArgs</code> should be a function");'
  - text: '<code>functionWithArgs(1,2)</code>应该输出<code>3</code>'
    testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(1,2); uncapture(); } assert(logOutput == 3, "<code>functionWithArgs(1,2)</code> should output <code>3</code>");'
  - text: '<code>functionWithArgs(7,9)</code>应该输出<code>16</code>'
    testString: 'if(typeof functionWithArgs === "function") { capture(); functionWithArgs(7,9); uncapture(); } assert(logOutput == 16, "<code>functionWithArgs(7,9)</code> should output <code>16</code>");'
  - text: 定义后,使用两个数字调用<code>functionWithArgs</code> 。
    testString: 'assert(/^\s*functionWithArgs\s*\(\s*\d+\s*,\s*\d+\s*\)\s*;/m.test(code), "Call <code>functionWithArgs</code> with two numbers after you define it.");'
Challenge Seed
// Example
function ourFunctionWithArgs(a, b) {
  console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5
// Only change code below this line.
Before Test
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
console.info('after the test');
Solution
// solution required