Basic JavaScript: Understanding Undefined Value returned from a Function

Tell us what’s happening:

I don’t understand this challenge very well, can someone please explain what this is about and help me fix the error Once both functions have ran, 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 line
var sum = 0;
function addFive() {
sum + 5;
}

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

addThree();
addFive();

Your browser information:

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

Challenge: Understanding Undefined Value returned from a Function

Link to the challenge:

undefined value is a condition where an expression does not have a correct value, although it is syntactically correct. An undefined value must not be confused with empty string, boolean “false” or other “empty” values.
You just have to write the function . Your function addFive doesn’t have any parameter then why are you passing parameter when you are calling Just complete the addFive function.

Take a closer look at this line:
sum + 5;

What am I supposed to add to the addFive function?

add sum = sum + 5 in the addFive function

1 Like

you also shouldn’t declare again sum, and you should have a total of 2 function calls, one for each function, you have three function calls

I did, but it still doesn’t equal to eight.
var sum = 0;
function addFive() {
sum = sum + 5
}

addThree();

Thanks I removed the last function and that fixed the issue.

please show the whole code in the editor, if you want to ask for help

pay attention to the comments about where you can change stuff (if needed reset code)

var sum = 0;

    function addThree() {

        sum = sum + 3;

        

    }

    // Only change code below this line

    addThree();

    console.log(sum, "<= sum")

    function addFive() {

        sum += 5;

    }

  var returnValue = addFive();

    // Only change code above this line

    console.log(sum, "<= sum");

This is an old thread. If you have a question about this code, please open a new topic and include some words describing what you want.