Basic JavaScript - Understanding Undefined Value returned from a Function

Here’s the question:
Create a function addFive without any arguments. This function adds 5 to the sum variable, but its returned value is undefined.

Can I please have the answer to this?

Thank you!

Your code so far

// Setup
let sum = 0;

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

// Only change code below this line


// Only change code above this line

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

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

Your browser information:

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

Challenge: Basic JavaScript - Understanding Undefined Value returned from a Function

Link to the challenge:

Here’s the error:
// running tests
Once both functions have run, the sum should be equal to 8.
// tests completed

How do I fix this?

did you delete this from the bottom?

addThree();
addFive();

Ya, I am sure I got this wrong. But I changed those 2 lines into these:
function addThree() {
sum = sum + 3;
};

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

How do I fix this to get the correct answer?

Oh I got it! Thanks for reminding!

first of all, you shouldn’t have changed those. you need to add those back or push the reset lesson button. Only change the code where the comment lines say to change code.
you actually typed the addFive() function correctly, but without the line: addFive();
it will never return your answer

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