Question on syntax

Tell us what’s happening:
Describe your issue in detail here.

When I couldn’t get my code to pass, I cheated and looked at the answer. In the correct code, (val++) was instead (val + 1). Everything else in my original code matched the solution offered. Is there a reason why (val++) doesn’t pass the test? Is there a limitation to the (++) syntax that I am unaware of? Am I missing something more obvious? Thanks in advance for any help.

  **Your code so far**

// The global variable
let fixedValue = 4;

// Only change code below this line
function incrementer(val) {
return val++;

// Only change code above this line
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36

Challenge: Pass Arguments to Avoid External Dependence in a Function

Link to the challenge:

Hi @TheRev !

You can use the increment operator and pass this challenge.
The problem is that you are using it incorrectly here.

This syntax will return the value before it increments.

This is the postfix increment.

If you changed your code to use the prefix increment like this then it will return the value after incrementing.

return ++val;

You can add this console.log to your code and play around with the postfix and prefixes to see the differences.

console.log(`result: ${incrementer(fixedValue)}`)
console.log(`fixedValue: ${fixedValue}`)

hope that helps!

1 Like

Did not know that. Thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.