# I found the right code but

Tell us what’s happening:
I found the right code, but when i remove a line the code become as semi complete
and if i remove another line is the other semi compleate.
So if you remove the line:
sum += 5;
I get an error: Inside the `addFive` function, you should add `5` to the `sum` variable
So i return it back.
And if i remove a part of a code line:
var result =
i get an error: Once both functions have ran, the `sum` should be equal to 8.

So What is the right code?

``````
// Setup
var sum = 3;

sum = sum + num;
}

// Only change code below this line
sum += 5;
}
// Only change code above this line

var result = addFive(); // This is undefined
console.log("Sum= " + sum);
``````

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

Challenge: Understanding Undefined Value returned from a Function

You have modified a portion of the code that you were not supposed to. I’d reset the challenge and only add the `addFive()` function. Your `addFive()` function is correct but you have changed how the `addThree()` function works.

Hey there!

What you have is correct if you are expecting the the final value of sum to be 13.

Note that you are changing the value of sum in the first function addThree(num),

So after you call that function the value of sum changes from 3 to 8 because you are passing an addition of 5 in that function call.

Then you are running addFive() function which then changes the value of sum to 13 as you are adding 5 to the value of 8.

and now the value of sum is 13.

if you do not want to change the value of global scope sum through your function then you have to return the function call as a new value which will not change the original global scope value.

``````// Setup
var sum = 3;

sum = sum + num;
}

// Only change code below this line
sum += 5
}

// Only change code above this line

var result = addFive(); // This is undefined
console.log("Sum= " + sum);
console.log("Sum= " + sum);
console.log("Sum= " + sum);
``````

Above, I am logging the value of sum to the console everytime I make a function call. See how the value of sum changes.

Now please see below how to not change the global scope variable outside the function.

``````// Setup
var sum = 3;

return sum + num;
}

// Only change code below this line
return sum + 5
}

// Only change code above this line

console.log("Sum= " + sum);
console.log("Sum= " + sum);
console.log("Sum= " + sum);
console.log("Sum= " + sum);
``````

Also please note that using “+=” operator changes the value of global scope sum. You are assigning a new value to the sum variable.

Also to address your query on result variable to be undefined. Below is the proper way to use the result variable for the simplicity.

``````var sum = 3

var result= sum +  5;
return result;
}

console.log(result);
``````

Hope this helps! Keep on advancing to further lessons as you will have clearer answer to some doubts from previous lessons as you further dig deeper into understanding the logic of functions.

Cheers!! Happy Coding!

So the tiny change was in line :

To everyone the correct code. Thnx.

// Setup
var sum = 3;
sum = sum + num;
}
// Only change code below this line