If we write the conditions of the task with RETURN statement, why the result is 11 and 13 for the relevent functions

Tell us what’s happening:
First I want to apologize for my inability to understand, thank you for you patience in advance.
I changed the code outside of the allowed lines just to see what would be the display of the result, after I used ‘console.log( )’. I did that for both of the functions, I got result 11 for function addThree() , and 13 for function addFive().
The question is: How does the code calculate these numbers, under the new conditions.
Thank You once again

Your code so far


// Setup
var sum = 0;

function addThree() {
return sum = sum + 3;
}

// Only change code below this line
function addFive() {
return sum = sum + 5;
}

// Only change code above this line

addThree();
addFive();
console.log(addThree());
console.log(addFive());

Your browser information:

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

Challenge: Understanding Undefined Value returned from a Function

Link to the challenge:

addThree();
// adds 3 to sum, so sum is 3.

addFive();
// adds 5 to sum, so sum is 8.

console.log(addThree());
// adds 3 to sum, so sum is 11 & prints it.

console.log(addFive());
// adds 5 to sum, so sum is 16 & prints it.
3 Likes

Thank you piedcipher for the fast and very clear answer. Now I got it. As I started the topic - Please accept my apology for that not that smart question.

1 Like

I’m glad I could help. Awesome! No need to apologize, buddy. It was a perfect question.