ok, let’s see if this helps.
The instructions provided are:
Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified.
and the lines of code we are interested in therefore are these:
return function increment(number, value) {
return number + value;
};
Right now if value is not specified, the function will fail, correct? (it expects someone to pass a number and a value and doesn’t handle it if value is not provided).
The exercise is teaching us a way to allow the function to handle it if someone only gives us ‘number’ and doesn’t give us ‘value’ when they call increment.
The method being taught is to set a ‘default value’ for a given parameter.
For eg. they gave us this:
function greeting(name = "Anonymous") {
return "Hello " + name;
}
If you pay attention to the ‘name’ parameter, there is an equal sign and a value of “Anonymous”
This part is saying, if ‘name’ is not given to us, assume that name is “Anonymous”
Does this seem clear?
Now when the function is called it will work even if i neglect the parameter like this:
greeting();
Then it will output ‘Hello Anonymous’
And it will also continue to work if I give it the name like this
greeting('hbar1st');
In the exercise they want you to change the ‘value’ parameter so it has a default.
Specifically
Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified.
So if I call increment like this:
increment(10,5);
It currently adds 10 with 5 (number is added to value)
But they want it to work differently if I neglect to provide value
increment(10);
In this case it should return 11.
So using the method they showed us (with the equal sign added to the parameter declaration)
do you think you can solve this now?
happy to help further if the above is not enough.