Skip to content

Commit f87c17d

Browse files
Barbara HunterBarbara Hunter
authored andcommitted
changes to callbacks.js changes to closure.js
1 parent 6808f67 commit f87c17d

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

assignments/callbacks.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2424

2525
function getLength(arr, cb) {
2626
// getLength passes the length of the array into the callback.
27+
return cb(arr.length);
2728
}
2829

30+
function myFunction(arrayLength){
31+
return arrayLength;
32+
}
33+
34+
getLength(items, myFunction);
35+
2936
function last(arr, cb) {
3037
// last passes the last item of the array into the callback.
38+
return cb(arr[arr.length - 1])
3139
}
3240

3341
function sumNums(x, y, cb) {

assignments/closure.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
33

4-
// const name = "Barbara";
4+
const name = "Barbara";
55

6-
// function myName(){
7-
// console.log (`My name is ${name}`);
8-
// }
6+
function myName(){
7+
console.log (`My name is ${name}`);
8+
}
99

10-
// myName();
10+
myName();
1111

1212

1313

0 commit comments

Comments
 (0)