Bug: Avoid Mutations and Side Effects Using Functional Programming needs to validate the global variable is used in the incrementer function
See original GitHub issueWhile reviewing a PR (#39363) that fixes a separate issue on the [Avoid Mutations and Side Effects Using Functional Programming](Avoid Mutations and Side Effects Using Functional Programming) challenge, I noticed the following test does not validate that the value returned from the incrementer
function returns a value that is one larger than the fixedValue
global variable’s value.
- text: Your <code>incrementer</code> function should return a value that is one larger than the <code>fixedValue</code> value.
testString: const newValue = incrementer(); assert(newValue === 5);
A user can simply write the following and pass the challenge without even using the fixedValue
variable in the code.
var fixedValue = 4;
function incrementer () {
// Only change code below this line
return 5;
// Only change code above this line
}
I suggest adding a third test, so that we set the value of fixedValue
to a different value before calling the function. However, since the user could technically write const fixedValue = 4;
instead of var fixedValue = 4;
, one way of approaching this would be to use an IIFE: like the following:
- text: Your <code>incrementer</code> function return a value based on the global `fixedValue` variable value.
testString: |
(function() {
const fixedValue = 10;
const newValue = incrementer();
assert(fixedValue === 10 && newValue === 11);
})()
Before adding a help wanted
label, I am looking for feedback from others about this approach to fixing the challenge.
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (14 by maintainers)
Top GitHub Comments
Ok Thanks 🙂🙂
On Tue, Sep 1, 2020, 20:32 Nicholas Carrigan notifications@github.com wrote:
@RandellDawson @Sky020 The call to incrementor function inside the IIFE does not refer to the fixedValue variable created inside IIFE. That’s why the assertion will give an error.