Tell us what’s happening:
I know this is early on so I don’t quite understand the purpose of the functional programming but so far, 3 lessons in, it sounds like the point is to have a function that doesn’t alter something outside of it. If so, why can’t I just use the increment operator ++ in my function? It still doesn’t change the global value but it’s considered wrong.
Your code so far
// the global variable
var fixedValue = 4;
// Add your code below this line
function incrementer (myValue) {
return myValue +1;
//return myValue++; is considered wrong
//Add your code above this line
}
var newValue = incrementer(fixedValue); // Should equal 5
console.log(fixedValue); // Should print 4
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36.
No I’m just curious why it fails even though it technically fulfills the requirements of the assignment and gives the correct response. Is it technically considered imperative to use ++, it’s not considered common practice in functional programming, it’s impolite, or it’s just not something the test was expecting?
It doesn’t fulfill the requirements though. It will not return the correct value if you use a post incrementor, which is what I was originally trying to explain.