Basic JavaScript - Understanding Undefined Value returned from a Function

que estoy haciendo mal ?

esto es lo que me dice ekl resultado del test:

//Once both functions have run, the sum should be equal to 8 .

// Setup
var sum = 0;

function addThree(sum) {
sum = sum + 3;
}

// Only change code below this line
addThree();
function addFive(sum) {
sum += 5;
}
// 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/103.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Understanding Undefined Value returned from a Function

Link to the challenge:

You changed the code in a way you were not asked to.

  1. Each function should only be called one time.

  2. The functions should not have a sum parameter.


A brief explanation of point 2

If you give the functions a sum parameter it will be used instead of the top-level sum variable, so the top-level variable will not change.

Secondly, because you are not providing the functions with an argument when you call them, sum inside the functions will be undefined. If you do math operations on undefined it results in NaN.

gracias pude resolverlo por tu ayuda :+1:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.