dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.6 KiB
1.6 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 598e8944f009e646fc236146 | Understanding Undefined Value returned from a Function | 1 | 301177 | understanding-undefined-value-returned-from-a-function |
--description--
A function can include the return statement but it does not have to. In the case that the function doesn't have a return statement, when you call it, the function processes the inner code but the returned value is undefined.
Example
let sum = 0;
function addSum(num) {
sum = sum + num;
}
addSum(3);
addSum is a function without a return statement. The function will change the global sum variable but the returned value of the function is undefined.
--instructions--
Create a function addFive without any arguments. This function adds 5 to the sum variable, but its returned value is undefined.
--hints--
addFive should be a function.
assert(typeof addFive === 'function');
Once both functions have run, the sum should be equal to 8.
assert(sum === 8);
Returned value from addFive should be undefined.
assert(addFive() === undefined);
Inside the addFive function, you should add 5 to the sum variable.
assert(
__helpers.removeWhiteSpace(addFive.toString()).match(/sum=sum\+5|sum\+=5/)
);
--seed--
--seed-contents--
// Setup
let sum = 0;
function addThree() {
sum = sum + 3;
}
// Only change code below this line
// Only change code above this line
addThree();
addFive();
--solutions--
let sum = 0;
function addThree() {
sum = sum + 3;
}
function addFive() {
sum = sum + 5;
}
addThree();
addFive();