Understanding-undefined-value-returned-from-a-function

Tell us what’s happening:

I don’t know why it gives me an error saying that sum should be equal to 8.

Your code so far



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

// Only change code below this line
function addFive(sum){

  sum = sum + 5;

}




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


Your browser information:

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

Link to the challenge:

1 Like

You are initially setting sum to 8, and then the function addFive sets it to 13 (because that’s what 8 + 5 is).

The function addFive should not take any argument.

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

// Only change code below this line

function addFive(){
sum = sum + 5;
}

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

You are calling the function addFive(3), but not returning anything from the functions.

notice what you wrote inside the()
(it shouldn’t be sum)

function addFive(sum)