Skip to content

Commit 033dea6

Browse files
committed
Not sure if the fifth question is supposed to be a stretch goal since nothing is marked specifically as a challenge
1 parent a0a64fa commit 033dea6

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ With some basic JavaScript principles in hand, we can now expand our skills out
1111

1212
### Task 2: Callbacks
1313
This task focuses on getting practice with callback functions by giving you an array of values and instructions on what to do with that array.
14-
* [ ] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your callback functions. **Remember that a callback function is a function that is being passed around to other functions.**
15-
* [ ] Write out each function using the `ES5` `function` keyword syntax.
16-
* [ ] Solve the problems listed. Save the stretch problems until you have completed Tasks 1-4.
14+
* [*] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your callback functions. **Remember that a callback function is a function that is being passed around to other functions.**
15+
* [*] Write out each function using the `ES5` `function` keyword syntax.
16+
* [*] Solve the problems listed. Save the stretch problems until you have completed Tasks 1-4.
17+
#### THERE ARE FIVE CHALLENGES PLUS STRETCH? || IS THE FIFTH CHALLENGE IS SUPPOSED TO BE STRETCH?
1718

1819

1920
### Task 3: Array Methods

assignments/callbacks.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,77 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2121
2222
*/
2323

24-
24+
// ========== Challenge 1 ?????????????
25+
console.log('========== Challenge 1 ?????????????');
2526
function getLength(arr, cb) {
2627
// getLength passes the length of the array into the callback.
28+
return cb(arr.length);
29+
}
30+
31+
const lengthSquared = function(length){
32+
return length * length;
2733
}
2834

35+
console.log(getLength(items, lengthSquared));
36+
37+
38+
39+
// ========== Challenge 2 ?????????????
40+
console.log('\n\n========== Challenge 2 ?????????????');
2941
function last(arr, cb) {
3042
// last passes the last item of the array into the callback.
43+
return cb(arr[arr.length - 1]);
3144
}
3245

46+
const lastItemCapped = function(lastItem){
47+
return lastItem.toUpperCase();
48+
}
49+
50+
console.log(last(items, lastItemCapped));
51+
52+
53+
54+
// ========== Challenge 3 ?????????????
55+
console.log('\n\n========== Challenge 3 ?????????????');
3356
function sumNums(x, y, cb) {
3457
// sumNums adds two numbers (x, y) and passes the result to the callback.
58+
return cb(x + y);
59+
}
60+
61+
const halved = function(whole){
62+
return whole / 2;
3563
}
3664

65+
console.log(sumNums(9, 7, halved));
66+
67+
68+
69+
70+
// ========== Challenge 4 ?????????????
71+
console.log('\n\n========== Challenge 4 ?????????????');
3772
function multiplyNums(x, y, cb) {
3873
// multiplyNums multiplies two numbers and passes the result to the callback.
74+
return cb(x * y);
3975
}
4076

77+
console.log(multiplyNums(9, 7, halved));
78+
79+
80+
81+
// ========== Challenge 5 ?????????????
82+
console.log('\n\n========== Challenge 5 ?????????????');
4183
function contains(item, list, cb) {
4284
// contains checks if an item is present inside of the given array/list.
4385
// Pass true to the callback if it is, otherwise pass false.
86+
4487
}
4588

89+
90+
91+
4692
/* STRETCH PROBLEM */
93+
// ========== Stretch Challenge
94+
console.log('\n\n========== Stretch Challenge ');
4795

4896
function removeDuplicates(array, cb) {
4997
// removeDuplicates removes all duplicate values from the given array.

index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Javascript II</title>
8+
9+
</head>
10+
<body>
11+
<h1>Javascript II</h1>
12+
13+
<h2>Callbacks</h2>
14+
<script src="assignments/callbacks.js"></script>
15+
16+
<h2>Array Methods</h2>
17+
<script src="assignments/array-methods.js"></script>
18+
19+
<h2>Closures</h2>
20+
<script src="assignments/closure.js"></script>
21+
22+
<h2>Stretch: Function Conversion</h2>
23+
<script src="assignments/stretch-function-conversion.js"></script>
24+
25+
</body>
26+
</html>

0 commit comments

Comments
 (0)