Skip to content

Commit a12c30c

Browse files
committed
WIP: Callback Challenge 3 Complete
1 parent 0c741be commit a12c30c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

assignments/callbacks.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,33 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2525
*/
2626

2727
// Challenge 1: getLength passes the length of the array into the callback.
28-
2928
function getLength (arr, cb) {
3029
cb(arr.length);
3130
}
32-
3331
getLength(items, (length) => {
3432
console.log(length);
3533
});
3634

35+
3736
// Challenge 2: last passes the last item of the array into the callback.
3837
function last(arr, cb) {
3938
cb(arr[arr.length - 1]);
4039
}
41-
4240
last(items, (last) => {
4341
console.log(last);
4442
});
4543

44+
4645
// Challenge 3: sumNums adds two numbers (x, y) and passes the result to the callback.
4746
function sumNums(x, y, cb) {
48-
47+
let add = x + y;
48+
cb(add);
4949
}
50+
sumNums(5, 10, (addNums) => {
51+
console.log(addNums);
52+
});
53+
54+
5055

5156
function multiplyNums(x, y, cb) {
5257
// multiplyNums multiplies two numbers and passes the result to the callback.

0 commit comments

Comments
 (0)