From e863759e29b315a2de0976282872ba26eaa939ce Mon Sep 17 00:00:00 2001 From: DusanSacha Date: Fri, 11 Aug 2017 13:45:32 +0200 Subject: [PATCH] feat(seed): Add new Basis JS Challenge Return Undefined Add new Bassis JS Challenge Return Undefined with all Change Requests --- .../basic-javascript.json | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) 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 569667685bf..f8ecdaac7c8 100644 --- a/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json +++ b/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json @@ -2646,6 +2646,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", + "
", + "Create a function 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",