Trying to understand this section

Tell us what’s happening:
Describe your issue in detail here.
// So although I got this right, I want to better understand it. The return value is undefined because I set punched in the code as to write the evaluation without an argument? Is that right?

  **Your code so far**

// Setup
var sum = 0;

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

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

// Only change code above this line

addThree();
addFive();
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15

Challenge: Understanding Undefined Value returned from a Function

Link to the challenge:

The return value is undefined because you didn’t specify a return. For example, you could have written:

function addThree() {
  return sum + 3;
}

That would return the value without changing the global variable sum. Some other things wold have to change to get it to work right, but that is the idea. And this is arguably a better pattern, one that I imagine you will study more in upcoming lessons.

2 Likes

Thank you Kevin so much! :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.