diff --git a/challenges/01-front-end-development-certification/basic-javascript.json b/challenges/01-front-end-development-certification/basic-javascript.json
index 4818cf354a..95c59ccac2 100644
--- a/challenges/01-front-end-development-certification/basic-javascript.json
+++ b/challenges/01-front-end-development-certification/basic-javascript.json
@@ -1709,17 +1709,16 @@
"description": [
"In JavaScript, we can divide up our code into reusable parts called functions.",
"Here's an example of a function:",
- "function functionName() {
",
- " console.log(\"Hello World\");
",
- "}
",
- "You can call or invoke this function by using its name followed by parenthese, like this:",
+ "
function functionName() {", + "You can call or invoke this function by using its name followed by parentheses, like this:", "
console.log(\"Hello World\");
}
functionName();
",
"Each time the function is called it will print out the message \"Hello World\" on the dev console. All of the code between the curly braces will be executed every time the function is called.",
"myFunction
which prints \"Hi World\" to the dev console. Call that function."
],
"tests": [
- "console.log(\"1 '\" + logOutput + \"'\", \"op: \" + /Hi World/.test(logOutput)); assert(\"Hi World\" === logOutput, 'message: myFunction
should output \"Hi World\"');",
- "assert(typeof myFunction === 'function', 'message: myFunction
should be a function');"
+ "assert(typeof myFunction === 'function', 'message: myFunction
should be a function');",
+ "assert(\"Hi World\" === logOutput, 'message: myFunction
should output \"Hi World\" to the dev console');",
+ "assert(/^\\s*myFunction\\(\\)\\s*;/m.test(editor.getValue()), 'message: Call myFunction
after you define it');"
],
"challengeSeed": [
"// Example",
@@ -1727,6 +1726,8 @@
" console.log(\"Heyya, World\");",
"}",
"",
+ "ourFunction();",
+ "",
"// Only change code below this line",
"",
""
@@ -1757,7 +1758,8 @@
"solutions": [
"function myFunction() {",
" console.log(\"Hi World\");",
- "}"
+ "}",
+ "myFunction();"
],
"type": "waypoint",
"challengeType": "1"
@@ -1767,17 +1769,34 @@
"title": "Passing Values to Functions with Arguments",
"description": [
"Functions can take input in the form of parameters. Parameters
are variables that take on the value of the arguments which are passed in to the function. Here is a function with two parameters, param1
and param2
:",
- "function testFunct(param1, param2) {
",
- " console.log(param1, param2);
",
- "}
",
- "Then we can call testFunction
:",
- "testFunction(\"Hello\", \"World\");
",
- "We have passed two arguments, \"Hello\" and \"World\". Inside the function, param1
will equal \"Hello\" and param2
will equal \"World\". Note that you could call testFunction
again with different arguments and the parameters would take on the value of the new arguments.",
- "myFunction
that accepts two arguements and outputs their sum to console.log
"
+ "function testFun(param1, param2) {", + "Then we can call
console.log(param1, param2);
}
testFun
:",
+ "testFun(\"Hello\", \"World\");
",
+ "We have passed two arguments, \"Hello\" and \"World\". Inside the function, param1
will equal \"Hello\" and param2
will equal \"World\". Note that you could call testFun
again with different arguments and the parameters would take on the value of the new arguments.",
+ "myFunction
that accepts two arguments and outputs their sum to the dev console. Call your function."
],
"releasedOn": "11/27/2015",
"tests": [
- "assert((function(){if(typeof(f) !== \"undefined\" && f === a + b){return true;}else{return false;}})(), 'message: Your function should ouput the value of a + b
.');"
+ "assert(typeof myFunction === 'function', 'message: myFunction
should be a function');",
+ "capture(); myFunction(1,2); uncapture(); assert(logOutput == 3, 'message: myFunction(1,2)
should output 3
');",
+ "capture(); myFunction(7,9); uncapture(); assert(logOutput == 16, 'message: myFunction(7,9)
should output 16
');",
+ "assert(/^\\s*myFunction\\(\\s*\\d+\\s*,\\s*\\d+\\s*\\)\\s*;/m.test(editor.getValue()), 'message: Call myFunction
after you define it');"
+ ],
+ "head": [
+ "var logOutput = \"\";",
+ "var oldLog = console.log;",
+ "function capture() {",
+ " console.log = function (message) {",
+ " logOutput = message + ''.trim();",
+ " oldLog.apply(console, arguments);",
+ " };",
+ "}",
+ "",
+ "function uncapture() {",
+ " console.log = oldLog;",
+ "}",
+ "",
+ "capture();"
],
"challengeSeed": [
"// Example",
@@ -1788,11 +1807,16 @@
"",
"// Only change code below this line.",
"",
- "",
""
],
"tail": [
- ""
+ "uncapture();",
+ "",
+ "if (typeof myFunction !== \"function\") { ",
+ " (function() { return \"myFunction is not defined\"; })();",
+ "} else {",
+ " (function() { return logOutput || \"console.log never called\"; })();",
+ "}"
],
"solutions": [
""
@@ -1809,19 +1833,60 @@
"id": "56533eb9ac21ba0edf2244be",
"title": "Global Scope and Functions",
"description": [
- "In Javascript, scope refers to the visibility of variables."
+ "In Javascript, scope refers to the visibility of variables. Variables which are defined outside of a function block have Global scope. This means the can be seen everywhere in your Javascript code. ",
+ "Variables which are used without the var
keyword are automatically created in the global
scope. This can create unintended concequences elsewhere in your code or when running a function again. You should always declare your variables with var
.",
+ "global
variable myGlobal
outside of any function. Initialize it to have a value of 10
",
+ "Inside function fun1
, assign 5
to oopsGlobal
without using the var
keyword."
],
"releasedOn": "11/27/2015",
"tests": [
- "assert(1===1, 'message: message here');"
+ "assert(typeof myGlobal != \"undefined\", 'message: myGlobal
should be defined');",
+ "assert(myGlobal === 10, 'message: myGlobal
should have a value of 10
');",
+ "assert(/var\\s+myGlobal/.test(editor.getValue()), 'message: myGlobal
should be declared using the var
keyword');",
+ "assert(typeof oopsGlobal != \"undefined\" && oopsGlobal === 5, 'message: oopsGlobal
should have a value of 5
');",
+ "assert(!/var\\s+oopsGlobal/.test(editor.getValue()), 'message: Do not decalre oopsGlobal
using the var
keyword');"
+ ],
+ "head": [
+ "var logOutput = \"\";",
+ "var oldLog = console.log;",
+ "function capture() {",
+ " console.log = function (message) {",
+ " logOutput = message;",
+ " oldLog.apply(console, arguments);",
+ " };",
+ "}",
+ "",
+ "function uncapture() {",
+ " console.log = oldLog;",
+ "}",
+ "",
+ "capture();"
],
"challengeSeed": [
+ "// Declare your variable here",
"",
"",
- ""
+ "function fun1() {",
+ " // Assign 5 to oopsGlobal Here",
+ "}",
+ "",
+ "// Only change code above this line",
+ "function fun2() {",
+ " var output = \"\";",
+ " if(typeof myGlobal != \"undefined\") {",
+ " output += \"myGlobal: \" + myGlobal;",
+ " }",
+ " if(typeof oopsGlobal != \"undefined\") {",
+ " output += \" oopsGlobal: \" + oopsGlobal;",
+ " }",
+ " console.log(output);",
+ "}"
],
"tail": [
- ""
+ "fun1();",
+ "fun2();",
+ "uncapture();",
+ "(function() { return logOutput || \"console.log never called\"; })();"
],
"solutions": [
""
@@ -1838,10 +1903,11 @@
"id": "56533eb9ac21ba0edf2244bf",
"title": "Local Scope and Functions",
"description": [
- "In Javascript, Scope
is the test of variables, object, and functions you have access to. Variables which are defined within a function and parameters are local, which means they are only visible within that function. ",
- "Here is a function test
with a local variable called loc
.",
- "function test() {", - "
var loc = \"foo\";
console.log(local1); // \"foo\"
}
test();
console.log(loc); // \"undefined\"
loc
is not defined outside of the function."
+ "Variables which are declared within a function, as well as function parameters are local. Thos means they are only visible within that function. ",
+ "Here is a function myTest
with a local variable called loc
.",
+ "function myTest() {", + "
var local1 = \"foo\";
console.log(local1);
}
myTest(); // \"foo\"
console.log(local1); // \"undefined\"
local1
is not defined outside of the function.",
+ "myVar
inside myFunction
"
],
"releasedOn": "11/27/2015",
"tests": [