diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.english.md index 6ce2ebb970b..f1d872ac2be 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function.english.md @@ -16,7 +16,7 @@ var sum = 0; function addSum(num) { sum = sum + num; } -var returnedValue = addSum(3); // sum will be modified but returned value is undefined +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. @@ -34,12 +34,12 @@ Create a function addFive without any arguments. This function adds tests: - text: addFive should be a function testString: assert(typeof addFive === 'function'); - - text: sum should be equal to 8 + - text: Once both functions have ran, the sum should be equal to 8 testString: assert(sum === 8); - text: Returned value from addFive should be undefined testString: assert(addFive() === undefined); - - text: Inside of your functions, add 5 to the sum variable - testString: assert(code.match(/(sum\s*\=\s*sum\s*\+\s*5)|(sum\s*\+\=\s*5)/g).length === 1); + - text: Inside the addFive function, add 5 to the sum variable + testString: assert(addFive.toString().replace(/\s/g, '').match(/sum=sum\+5|sum\+=5/)); ``` @@ -59,37 +59,34 @@ function addThree() { // Only change code below this line - - // Only change code above this line -var returnedValue = addFive(); -``` - - - - -### After Test -
- -```js -var sum = 0; -function addThree() {sum = sum + 3;} addThree(); addFive(); ```
- ## Solution
```js -function addFive() { - sum = sum + 5; +// Example +var sum = 0; +function addThree() { + sum = sum + 3; } + +// Only change code below this line + +function addFive() { + sum = sum + 5; +} + +// Only change code above this line +addThree(); +addFive(); ```