I m stuck for a long time with that need help with explaning
**Your code so far**
// Setup
let sum = 3;
function addThree(sum) {
return sum = sum + 3;
}
// Only change code below this line
function addFive (sum) {
sum +5 ;
}
// Only change code above this line
addThree();
addFive();
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Challenge: Understanding Undefined Value returned from a Function
The variable name, and the function parameter shall not be the same word.
The function as it’s written here will return 6, because “sum” has assigned 3 as a value to it.
and because you’re using the “return” keyword.
the goal of the challenge is to change the value of the variable, but return nothing as result from the function.
That is achieved if you don’t use return in your functions.
Also you do not need to use parameters for this challenge.
Your function doesn’t have an explicit return statement. What does a function in JS return if there is no return statement? You should be able to easily google the answer if you don’t know.
i know isn’t needed it was trying to test something >>here what i had achieved i get 2 true point out of 4 from task completion points <<and here the notes of failure
1
Inside the addFive function, you should add 5 to the sum variable.
Once both functions have run, the sum should be equal to 8 .
Your code so far
// Setup
let sum = 0 ;
function addThree(sum) {
sum = sum + 3;
}
// Only change code below this line
function addFive (sum) {
sum + 5 ;
}
// Only change code above this line
addThree();
addFive();
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Challenge: Understanding Undefined Value returned from a Function
// Setup
let sum = 0;
function addThree() {
sum = sum + 3;
}
// Only change code below this line
// Only change code above this line
addThree();
addFive();
You change the function signature of addThree()! You made sum an argument which turns sum into a variable scoped locally to the function, but the challenge wants you to change the global variable sum.
// Setup
let sum = 8 ;
function addThree(sum) {
sum = sum + 3;
}
// Only change code below this line
function addFive (sum) {
sum = sum + 5 ;
}
// Only change code above this line
addThree();
addFive();
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
Like I said, you can use it, but it is not required. I try not to tell people that they must do things that are not part of or needed for the challenge. It can lead to confusion.
I’ll sometimes comment on style and make “you should” comments though.