Files

41 lines
941 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Avoid Mutations and Side Effects Using Functional Programming
---
# 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.
---
## 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.
---
## 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;
function incrementer() {
2018-10-12 15:37:13 -04:00
// Add your code below this line
return fixedValue + 1;
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
```
</details>