Why i can't Incrementation one argument?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0.

Challenge: Pass Arguments to Avoid External Dependence in a Function

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function

Hi,
This solution is very simple but what i don’t understand is why can’t implementation in this way vauer++? ( value is the parameter ).

1 Like

We would need to see your full code for this challenge to comment further.

1 Like
// the global variable
var fixedValue = 4;

// Add your code below this line
function incrementer (value) {
      return value++; // no correct 

  // Add your code above this line
}

var newValue = incrementer(fixedValue); // Should equal 5
console.log(fixedValue); // Should print 4

1 Like

Because when ++ is after the variable name, the current value of the variable named gets returned and then the value of it is incremented. You can use value++ as one statement and then return value in another statement, because then value will have already incremented.

If you want to increment the value and return the incremented value in the same line, you can put the ++ before the variable name.

2 Likes