diff --git a/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json b/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
index bc93629b60..cad378bac5 100644
--- a/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
@@ -2654,6 +2654,51 @@
}
}
},
+ {
+ "id": "598e8944f009e646fc236146",
+ "title": "Understanding Undefined Value returned from a Function",
+ "description": [
+ "A function can include the return
statement but it does not have to. In the case that the function doesn't have a return
statement, when you call it, the function processes the inner code but the returned value is undefined
.",
+ "Example",
+ "
var sum = 0;", + "
function addSum(num) {
sum = sum + num;
}
var returnedValue = addSum(3); // sum will be modified but returned value is undefined
addSum
is a function without a return
statement. The function will change the global sum
variable but the returned value of the function is undefined
",
+ "addFive
without any arguments. This function adds 5 to the sum
variable, but its returned value is undefined
."
+ ],
+ "releasedOn": "August 11, 2017",
+ "challengeSeed": [
+ "// Example",
+ "var sum = 0;",
+ "function addThree() {",
+ " sum = sum + 3;",
+ "}",
+ "",
+ "// Only change code below this line",
+ "",
+ "",
+ "",
+ "// Only change code above this line",
+ "var returnedValue = addFive();"
+ ],
+ "tail": [
+ "var sum = 0;",
+ "function addThree() {sum = sum + 3;}",
+ "addThree();",
+ "addFive();"
+ ],
+ "solutions": [
+ "function addFive() {\n sum = sum + 5;\n}"
+ ],
+ "tests": [
+ "assert(typeof addFive === 'function', 'message: addFive
should be a function');",
+ "assert(sum === 8, 'message: sum
should be equal to 8');",
+ "assert(addFive() === undefined, 'message: Returned value from addFive
should be undefined
');",
+ "assert(code.match(/(sum\\s*\\=\\s*sum\\s*\\+\\s*5)|(sum\\s*\\+\\=\\s*5)/g).length === 1, 'message: Inside of your functions, add 5 to the sum
variable');"
+ ],
+ "type": "waypoint",
+ "challengeType": 1,
+ "translations": {}
+ },
{
"id": "56533eb9ac21ba0edf2244c3",
"title": "Assignment with a Returned Value",