Merge pull request #7856 from erictleung/fix/usability-on-local-scope-and-functions

Clarify instructions for Local Scope and Functions
This commit is contained in:
Rex Schrader 2016-04-03 14:11:29 -07:00
commit 87ebb3517b

View File

@ -2262,23 +2262,24 @@
"<blockquote>function myTest() {<br> var loc = \"foo\";<br> console.log(loc);<br>}<br>myTest(); // \"foo\"<br>console.log(loc); // \"undefined\"</blockquote>",
"<code>loc</code> is not defined outside of the function.",
"<h4>Instructions</h4>",
"Declare a local variable <code>myVar</code> inside <code>myFunction</code>"
"Declare a local variable <code>myVar</code> inside <code>myFunction</code>. Run the tests and then follow the instructions commented out in the editor.",
"<strong>Hint</strong><br>Refreshing the page may help if you get stuck."
],
"releasedOn": "January 1, 2016",
"head": [
"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);",
" }",
" };",
" 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() {",
@ -2295,11 +2296,11 @@
"}",
"myFunction();",
"",
"// run and check the console ",
"// Run and check the console",
"// myVar is not defined outside of myFunction",
"console.log(myVar);",
"",
"// now remove the console log line to pass the test",
"// Now remove the console log line to pass the test",
""
],
"tail": [