2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Pass Arguments to Avoid External Dependence in a Function
|
|
|
|
---
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
# Pass Arguments to Avoid External Dependence in a Function
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
Try to pass argument to function and return increased value of this argument.
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
```javascript
|
2018-10-12 15:37:13 -04:00
|
|
|
// the global variable
|
|
|
|
var fixedValue = 4;
|
|
|
|
|
|
|
|
// Add your code below this line
|
2019-07-24 00:59:27 -07:00
|
|
|
function incrementer(value) {
|
2018-10-12 15:37:13 -04:00
|
|
|
return value + 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(fixedValue); // Should equal 5
|
|
|
|
console.log(fixedValue); // Should print 4
|
|
|
|
```
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
#### Code Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
This code will provide the same result as the last challenge, only this time we will pass the `fixedValue` into the function as a parameter.
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|
2018-10-12 15:37:13 -04:00
|
|
|
|