ES6 - Set Default Parameters for Your Functions

ES6 - Set Default Parameters for Your Functions
0

#1

Hello! I have a problem with the challenge ES6 - Set Default Parameters for Your Functions.

They ask:
Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified.

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


I did it like this and it doesn't work, what am I doing wrong (only the first line is changed)?

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

#2

share the challenge link.


#3

You are adding the default parameter at wrong place.

Try this

const increment = (function() {
      “use strict”;
      return function increment(number, value=1) { 
             return number + value;
      };
})();

#4

This worked, thank you!


#5

Try this: It worked.

function increment (number, value = 1) {
return number + value;
};


#6

Sorry Guys I have a question dealing this quiz I did it as it supposed to be but keep returning a NaN output to me when I change the value to value = 1 it worked why? it shouldn’t be like that I guess??


#7

If you go to the challenge and click on the ask for help button it will open a new topic that includes your code. Maybe someone will spot the error