* 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.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244bf | Local Scope and Functions | 1 | 本地范围和功能 |
Description
myTest
带有一个名为loc
的局部变量。 function myTest(){
var loc =“foo”;
的console.log(LOC);
}
MYTEST(); //记录“foo”
的console.log(LOC); // loc未定义
loc
未在函数外定义。 Instructions
myLocalScope
声明一个局部变量myVar
。运行测试,然后按照编辑器中注释的说明进行操作。 暗示 如果您遇到问题,刷新页面可能会有所帮助。
Tests
tests:
- text: 没有全局<code>myVar</code>变量
testString: assert(typeof myVar === 'undefined');
- text: 添加本地<code>myVar</code>变量
testString: assert(/function\s+myLocalScope\s*\(\s*\)\s*\{\s[\s\S]+\s*var\s*myVar\s*(\s*|=[\s\S]+)\s*;[\s\S]+}/.test(code));
Challenge Seed
function myLocalScope() {
'use strict'; // you shouldn't need to edit this line
console.log(myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);
// Now remove the console log line to pass the test
Before Test
var logOutput = "";
var originalConsole = console
function capture() {
var nativeLog = console.log;
console.log = function (message) {
logOutput = message;
if(nativeLog.apply) {
nativeLog.apply(originalConsole, arguments);
} else {
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
nativeLog(nativeMsg);
}
};
}
function uncapture() {
console.log = originalConsole.log;
}
After Test
console.info('after the test');
Solution
// solution required