* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.3 KiB
2.3 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56bbb991ad1ed5201cd392cf | Write Reusable JavaScript with Functions | 1 | 用函数编写可重用的JavaScript |
Description
function functionName(){您可以使用其名称后跟括号来调用或调用此函数,如下所示:
console.log(“Hello World”);
}
functionName();
每次调用该函数时,它都会在开发控制台上打印出"Hello World"
消息。每次调用函数时,都会执行大括号之间的所有代码。 Instructions
- 创建一个名为
reusableFunction
的函数,它将"Hi World"
打印到开发控制台。 - 调用该功能。
Tests
tests:
- text: <code>reusableFunction</code>应该是一个函数
testString: assert(typeof reusableFunction === 'function');
- text: <code>reusableFunction</code>应该将“Hi World”输出到开发控制台
testString: assert(hiWorldWasLogged);
- text: 定义后调用<code>reusableFunction</code>
testString: assert(/^\s*reusableFunction\(\)\s*/m.test(code));
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