3.5 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.5 KiB
		
	
	
	
	
	
	
	
id, title, challengeType, videoUrl, localeTitle
| id | title | challengeType | videoUrl | localeTitle | 
|---|---|---|---|---|
| 56533eb9ac21ba0edf2244bd | Passing Values to Functions with Arguments | 1 | Pasando valores a funciones con argumentos | 
Description
param1 y param2 : función testFun (param1, param2) {Luego podemos llamar a
console.log (param1, param2);
}
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
-  Cree una función llamada functionWithArgsque acepte dos argumentos y envíe su suma a la consola dev.
- Llame a la función con dos números como argumentos.
Tests
tests:
  - text: <code>functionWithArgs</code> debería ser una función
    testString: 'assert(typeof functionWithArgs === "function", "<code>functionWithArgs</code> should be a function");'
  - text: '<code>functionWithArgs(1,2)</code> debe generar <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> debe dar salida a <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: Llame a <code>functionWithArgs</code> con dos números después de definirlo.
    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