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
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??
This challenge has now been reworked, using arrow functions. This makes the code much smaller, and the answer to the challenge much easier. This is what I have:
My apologies. I had seen two others with answers listed, so I thought it was perfectly acceptable to do. In the future, I’ll be sure to not participate with providing solutions, like other users.