Why Is My Simple Answer Not The Answer Expected By Free Code Camp JS challenge: Set Default Parameters for Your Functions?

Tell us what’s happening: My answer accepted for this challenge is a lot simpler than the expected answer on the solutions page. Can anyone think why my answer wouldn’t be the desired answer???
All answers welcome, thank you!

Your code so far


function increment(num1, value=1) {  
    return num1 + value;
  };
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns 6

Solution From Get A Hint Page

const increment = (function() {
  "use strict";
  return function increment(number, value = 1) {
    return number + value;
  };
})();
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns NaN

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions

You have changed the environment, the tests check what you have written exactly

Next version of the challenge will remove the outer function as it is not necessary anymore (it was for the tests) and your solution should be accepted

1 Like

Your answer works fine? Try refeshing the browser/clearing the cache.