2018-10-12 15:37:13 -04:00
---
title: Avoid Mutations and Side Effects Using Functional Programming
---
2019-07-24 00:59:27 -07:00
# Avoid Mutations and Side Effects Using Functional Programming
---
## Problem Explanation
2018-10-12 15:37:13 -04:00
Fill in the code for the function `incrementer` so it returns the value of the global variable `fixedValue` increased by one. `fixedValue` should not change, no matter how many times the function `incrememter` is called.
2019-07-24 00:59:27 -07:00
---
## Hints
2018-10-12 15:37:13 -04:00
### Hint 1
Using the increment operator (`++` ) on `fixedValue` will mutate `fixedValue` , meaning it will no longer reference the same value it was assigned with.
2019-07-24 00:59:27 -07:00
---
## Solutions
< details > < summary > Solution 1 (Click to Show/Hide)< / summary >
2018-10-12 15:37:13 -04:00
```javascript
// the global variable
var fixedValue = 4;
2019-07-24 00:59:27 -07:00
function incrementer() {
2018-10-12 15:37:13 -04:00
// Add your code below this line
return fixedValue + 1;
2019-07-24 00:59:27 -07:00
2018-10-12 15:37:13 -04:00
// Add your code above this line
}
var newValue = incrementer(); // Should equal 5
console.log(fixedValue); // Should print 4
```
2019-07-24 00:59:27 -07:00
< / details >