Hello. Why is this challenge important…what do we use this knowledge for because it doesn’t seem useful to me in the future. Or perhaps it’s because I still don’t understand the purpose of this exercise…which is why I might need my function not to return anything but instead just change some global variable?
EXAMPLE 1:
// Setup
let sum = 0;
function addThree() {
sum = sum + 3;
}
// Only change code below this line
function addFive() {
sum = sum + 5;
}
// Only change code above this line
console.log(sum);
addThree();
console.log(addThree());
console.log(sum);
addFive();
console.log(addFive());
console.log(sum);
EXAMPLE 2:
// Setup
let sum = 0;
function addThree() {
return sum = sum + 3;
}
// Only change code below this line
function addFive() {
return sum = sum + 5;
}
// Only change code above this line
console.log(sum);
addThree();
console.log(addThree());
console.log(sum);
addFive();
console.log(addFive());
console.log(sum);
*So why would you need to avoid using a return statement when it makes much of a difference ‘to the function’ than not using it ,since when you do, it returns a ‘value’ than returning ‘undefined’…which Kinda sucks…please help me
Challenge: Understanding Undefined Value returned from a Function
**Link to the challenge:**https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/understanding-undefined-value-returned-from-a-function