1.6 KiB
1.6 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56bbb991ad1ed5201cd392cf | Write Reusable JavaScript with Functions | 1 |
Description
undefined
Instructions
undefined
Tests
tests:
- text: ''
testString: 'assert(typeof reusableFunction === "function", "<code>reusableFunction</code> should be a function");'
- text: ''
testString: 'assert("Hi World" === logOutput, "<code>reusableFunction</code> should output "Hi World" to the dev console");'
- text: ''
testString: 'assert(/^\s*reusableFunction\(\)\s*;/m.test(code), "Call <code>reusableFunction</code> after you define it");'
Challenge Seed
// Example
function ourReusableFunction() {
console.log("Heyya, World");
}
ourReusableFunction();
// 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 && message.trim) logOutput = 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