Value returned from a Function

Tell us what’s happening:
Describe your issue in detail here.
Error [Once both functions have run, the sum should be equal to 8 .]

  **Your code so far**

// Setup
var sum = 0;

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

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

// Only change code above this line
var result = addFive(3);
addThree();
addFive();
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36

Challenge: Understanding Undefined Value returned from a Function

Link to the challenge:

You’re mixing two contradicting concepts in one place. This function definition and call match okay

function addThree() { //no parameters
  sum = sum + 3;
}

addThree();

Function addThree has no parameters, so the function call addThree is passing no argument. They match.
Function addFive must accept no arguments, so it’s definition is

function addFive() {
...
}

Don’t change this structure (just complete the function body), because you are not allowed to change it, so the call at the bottom addFive() matches with the definition. This function adds 5 to the global variable sum and returns undefined (meaning there’s no return statement).
The call to addFive() is already there. Remove

var result = addFive(3);

because it is not matching or compatible with what’s already given there.

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