Error in "Undefined Value returned from a Function"?

Error in "Undefined Value returned from a Function"?
0

#1

Tell us what’s happening:

I’m passing the test with the below code just fine. However, I think the test condition "sum should be equal to 8" is incorrect.

Since the given code never execute addThree(), sum should be 5 at the end of the code, not 8.

Am I incorrect in thinking so?

Your code so far


// Example
var sum = 0;
function addThree() {
  sum = sum + 3;
}

// Only change code below this line

function addFive() {
  sum += 5;
}

console.log(sum);

// Only change code above this line
var returnedValue = addFive();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function


#2

That is a great observation and would be true based only on the code you can see in the challenge. However, behind the scenes for that particular test, they actually exectute the addThree function before your addFive function runs, which is why they are testing for sum to be 8.


#3

@RandellDawson, That makes sense.

If that’s the case, I suggest reflecting that in the given code by adding addThree() above the returnedValue assignment line, below the comment noting the student to edit only the above.