**Tell us what’s happening:**some one please help me here. what im i supposed to do? thanks Your code so far
// Setup
let sum = 0;
function addThree() {
sum = sum + 3;
}
// Only change code below this line
function addFive(){
sum += 5;
}
sum = addFive();
// 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/114.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Understanding Undefined Value returned from a Function
You don’t need to assign the function to the ‘sum’ variable. That variable is global. By invoking functions at the bottom of the code, the global ‘sum’ variable gets the value of 8, but the returned value of each function is undefined .
The following is an example where one of the functions has the return statement. The difference in the output is obvious:
// Setup
let sum = 0;
function addThree() {
sum = sum + 3;
}
// Only change code below this line
function addFive(){
sum += 5;
return "It is Ok";
}
// Only change code above this line
console.log(addThree());
console.log(addFive());
console.log(sum);
CONSOLE
›undefined ----the output of the first function when printed in the console
›It is Ok ----the output of the second function when printed in the console (added the return statement)
›8 ---- the value of the variable "sum" when printed in the console