Functional Programming: Pass Arguments to Avoid External Dependence in a Function

Alright, does anybody have any idea, what is wrong with the code?
The function is supposed to return a value, bigger than fixedValue by 1.

// the global variable
var fixedValue = 4;

// Add your code below this line
function incrementer(value) {
return value + 1;

// Add your code above this line
}

var newValue = incrementer(fixedValue); // Should equal 5
console.log(fixedValue);
console.log(newValue); // Should print 4

Challenge: Pass Arguments to Avoid External Dependence in a Function

Link to the challenge:

You added an argument to incrementer, but you were not supposed to. You need to reference the global variable fixedValue.

image

HI!~ :smiley:

I think you’re supposed to add an argument?

Oh, I must have mixed up the challenges… odd…

Well, I did… that was the point of the challenge - not to use fixedValue and pass it as an argument to the said function.
It returned 5 as it should have , but somehow marks it as false (i.e it doesn’t think that it returns 5)

Now I see whats wrong…

// Only change code below this line
function incrementer () {


  // Only change code above this line

You changed code outside of these lines. That messes with the test suite in this case.

Totally beat me to it. :smiley:

1 Like

I actually resorted to the ‘solution’ variant, which solves the challenge if you can’t do it by yourself. Still it isn’t fatal but rather comical :smiley:

You mean the solution provided on the “Get a Hint” post?

While that code will pass the tests, I strongly advise against copying the solution to complete the lesson. Copy-Pasting the solution severely inhibits your learning - the idea is to understand how the code works, rather than just passing the tests.

1 Like

I agree, I only resort to it, when I can’t think my way out of it. Writing it rather than copying also makes it better in my opinion.

Brusli,

I copied the code than you wrote, but I am still having problems.

I cant not pass yo the next lesson.

Please help me

What is the mistake?

I solve the problem

Thanks

1 Like

Sorry, about that. I’m glad that you figured it out.