// // Setup
// let sum = 5;
// function addThree() {
// sum = sum + 3;
// }
// function addFive()
// {
// sum +=5;
// }
// // Only change code below this line
// // Only change code above this line
// addThree();
// addFive();
let sum = 0;
function addThree(sum) {
sum = sum + 3;
}
function addFive(sum) {
sum += 5;
}
addFive(5);
addThree(3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Basic JavaScript - Understanding Undefined Value returned from a Function
If you add parameters to the functions they have to be called with arguments. When the functions are called by the test it calls them with no arguments and the parameters will be undefined.
Also, just to be clear. sum the parameter and sum the top-level variable are two different variables. Parameters are always used before any top-level variables. It looks inside the closest scope (i.e. the function) and moves out from there. When it finds sum inside the function it uses that, not the top-level variable. As said, sum is always undefined when the test calls the functions.
Remove the sum parameters from the function definitions.