Basic javascript : undefined value returned from a function

Hi! I’m doing this exercise but I do not get it

// 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

var returnedValue = addFive();

addThree();

addFive();

when I run the test it says: " // running tests Once both functions have ran, the

sum

should be equal to 8. // tests completed"


// 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
var returnedValue = addFive();
addThree();
addFive();

Your browser information:

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

Challenge: Understanding Undefined Value returned from a Function

Link to the challenge:

Hello!

Welcome to the forum :partying_face:!

It’s failing because you’re calling addFive twice:

var returnedValue = addFive(); // First call
addThree();
addFive(); // Second call

Hence 5 + 3 + 5 = 13 not 8.

The editor gives some hints as to what to do, and you ignored this:

// Only change code above this line

Hope it helps :slight_smile:,

Regards!