You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Week1/README.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,8 @@ In week two we will discuss the following topics:
10
10
```
11
11
12
12
## How to get started
13
-
1. Download and install the latest Current version of NodeJS - from https://nodejs.org/en/download/current/
14
-
To test that it was installed and running properly, go to your terminal and run the command: node -v You should get the node version printed on your terminal, for example, v8.8.0
13
+
1. Download and install the *LTS*version of NodeJS - https://nodejs.org/en/download/
14
+
To test that it was installed and running properly, go to your terminal and run the command: node -v You should get the node version printed on your terminal, for example, v8.9.1
15
15
2. Although you are free to make you own choice of text/code editor to use during class and homework, we have good experiences with Microsoft's free VSCode editor, which is supported on Windows, Mac and Linux. Please refer to our [VSCode Tips](../VSCodeTips/README.md) for more information.
16
16
17
17
## Here are resources that we like you to read as a preparation for the coming lecture:
Copy file name to clipboardExpand all lines: Week6/MAKEME.md
+93-50Lines changed: 93 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -19,84 +19,93 @@ Give feedback on `step 2` of `week 5` to one of your fellow students (do this by
19
19
20
20
[Make these assignments](https://github.com/HackYourFuture/Git/blob/master/Lecture-3.md). For handing in homework follow the Forking workflow that is described in our lecture-3.md file of HackYourFuture’s Git repository (there is also a video that explains this).
- Everything you wanted to know about [JavaScript scope](https://toddmotto.com/everything-you-wanted-to-know-about-javascript-scope/)
27
+
- JavaScript [Scoping and Hoisting](http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html)
28
+
- 5 JavaScript [“Bad” Parts That Are Fixed In ES6](https://medium.freecodecamp.com/5-javascript-bad-parts-that-are-fixed-in-es6-c7c45d44fd81)
29
+
30
+
- More about [closures](https://www.reddit.com/r/learnjavascript/comments/1v6n8p/closure_explain_likei_am_in_high_school/?st=ixsp0mbe&sh=5526d150)
31
+
- A VERY popular [StackOverflow article](http://stackoverflow.com/questions/111102/how-do-javascript-closures-work)
32
+
33
+
## Step 4: JavaScript
24
34
25
35
_Deadline Wednesday_
26
36
27
-
1. We saw that we can pass functions as arguments to other functions. Your task is to write a function that takes another function as an argument and runs it.
28
-
29
-
```js
30
-
functionfoo(func) {
31
-
// What to do here?
32
-
}
33
-
34
-
functionbar() {
35
-
console.log('Hello, I am bar!');
36
-
}
37
-
38
-
foo(bar);
39
-
```
40
-
41
-
2. We learned a little bit about callbacks inJS. A callback is simply a function passed to another function that gets executed (run) after a potentially long running operation has completed. There is another function called `setTimeout` that will wait a specified period of time and then execute a function. For example:
42
-
43
-
```js
44
-
function doIt() {
45
-
console.log('I am done');
37
+
1\.We saw that we can pass functions as arguments to other functions. Your task is to write a function that takes another function as an argument and runs it.
38
+
39
+
function foo(func) {
40
+
// What to do here?
41
+
}
42
+
43
+
function bar() {
44
+
console.log('Hello, I am bar!');
46
45
}
47
-
setTimeout(doIt, 5000)
48
-
```
49
-
If you run the above code it will wait 5 seconds and print `I am done`. Please read something about setTimeout on MDN. The first argument to the `setTimeout` call is the callback (`doIt`)
46
+
47
+
foo(bar);
50
48
51
-
You must write a function that takes 4 arguments.
49
+
2\.We learned a little bit about callbacks in JS. A callback is simply a function passed to another function that gets executed (run) after a potentially long running operation has completed. There is another function called `setTimeout` that will wait a specified period of time and then execute a function. For example:
50
+
51
+
```js
52
+
functiondoIt() {
53
+
console.log('I am done');
54
+
}
55
+
setTimeout(doIt, 5000)
56
+
```
57
+
58
+
If you run the above code it will wait 5 seconds and print `I am done`. Please read something about setTimeout on MDN. The first argument to the `setTimeout` call is the callback (`doIt`)
59
+
60
+
You must write a function that takes 4 arguments.
52
61
- A start value
53
62
- An end value
54
63
- A callback to call if the number is divisible by 3
55
64
- A callback to use if the number is divisible by 5
56
65
57
-
The function should generate an array containing values from start value to end value (inclusive).
66
+
The function should generate an array containing values from start value to end value (inclusive).
58
67
59
-
Then the function should iterate over the array and call the second argument if the array value is divisible by 3
68
+
Then the function should iterate over the array and call the first callback if the array value is divisible by 3
60
69
61
-
The function should call the second argument if the array value is divisible by 5
70
+
The function should call the second callback if the array value is divisible by 5
62
71
63
-
Both functions should be called if the array value is divisible by both 3 and 5
72
+
Both functions should be called if the array value is divisible by both 3 and 5
64
73
65
-
```js
66
-
THIS IS FAKE CODE
67
-
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
68
-
// make array
69
-
// start at beginning of array and check if you should call threeCallback or fiveCallback or go on to next
6. We did some work with arrays -`var arr = [1,2,3]`
99
+
6\. We did some work with arrays - `var arr = [1,2,3]`
91
100
We can also nest arrays inside arrays like this `var arr2d = [[1,2], [3,4], [5,6]]` (for math people you can think of this as a matrix)
92
101
How would you print all the items of an array with 3 dimensions?
93
102
How about with K dimensions?
94
103
What if you didn't know how deep the array was nested? (You don't have to write code for this but think about it)
95
104
96
-
7. Here are two functions that look like they do the something similar but they print different results. Please explain what's going on here.
105
+
7\. Here are two functions that look like they do the something similar but they print different results. Please explain what's going on here.
97
106
98
107
```js
99
-
var x = 9;
108
+
let x =9;
100
109
functionf1(val) {
101
110
val = val+1;
102
111
return val;
@@ -105,7 +114,7 @@ f1(x);
105
114
console.log(x);
106
115
107
116
108
-
var y = { x: 9 };
117
+
let y = { x:9 };
109
118
functionf2(val) {
110
119
val.x=val.x+1;
111
120
return val;
@@ -116,10 +125,44 @@ console.log(y);
116
125
If you are confused please run the code and then consult the Google for "javaScript pass by value pass by reference"
117
126
118
127
128
+
## Step 5: Scope and Closures
129
+
130
+
> Let's continue to learn a little more about scope and Closures.
131
+
132
+
133
+
1. Write a function that would allow you to do this:
134
+
```js
135
+
let addSix =createBase(6);
136
+
addSix(10); // returns 16
137
+
addSix(21); // returns 27
138
+
```
139
+
140
+
2. You will need to create an HTML document out of the below snippet to run the below code. A hint - the code is syntactically correct but doesn't do what you would expect. Can you see why and fix it?
141
+
142
+
Don't cheat - but if you get stuck ... http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example
143
+
144
+
```html
145
+
<buttonid="btn-0">Button 1!</button>
146
+
<buttonid="btn-1">Button 2!</button>
147
+
<buttonid="btn-2">Button 3!</button>
148
+
149
+
<scripttype="text/javascript">
150
+
151
+
let prizes = ['A Unicorn!', 'A Hug!', 'Fresh Laundry!'];
152
+
for (let btnNum =0; btnNum <prizes.length; btnNum++) {
153
+
// for each of our buttons, when the user clicks it...
__Bonus__: Write a function takes this array `['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']` and returns an array which only has unique values in it (so it removes the duplicate ones). Make it a 'smart' algorithm that could do it for every array (only strings/number). Try to make it as fast as possible!
Copy file name to clipboardExpand all lines: Week7/MAKEME.md
+47-12Lines changed: 47 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,10 @@
3
3
```
4
4
Topics discussed this week:
5
5
• Object Oriented Programming
6
+
• this
7
+
• call
8
+
• apply
9
+
• bind
6
10
• Code flow (order of execution)
7
11
• Async VS Sync
8
12
```
@@ -15,7 +19,7 @@ _Deadline Monday_
15
19
16
20
Give feedback on the SPA (Github API) and git branching homework of one of you fellow students. Please provide the feedback in an issue.
17
21
18
-
## Step 3: Issues
22
+
## Step 2: Issues
19
23
20
24
- Solve all your Git issues. DO NO CLOSE AN ISSUE WITHOUT AN EXPLANATION OR CODE COMMIT REFERENCING THAT ISSUE.
21
25
@@ -24,31 +28,62 @@ Give feedback on the SPA (Github API) and git branching homework of one of you f
24
28
25
29
- Fix the issues from the last week and make sure you explain how you fixed the issue in a comment (or commit message)
26
30
27
-
## Step 3: Some Challenges
31
+
## Step 4: Some Challenges
28
32
29
33
_Deadline Saturday_
30
34
31
35
Let's practice working with Objects and Arrays. Go to FreeCodeCamp and complete all challenges under "Object Oriented and Functional Programming" and the _first four challenges_ under "Basic Algorithm Scripting", up until 'Find the longest word in a string.'
32
36
33
-
## Step 4: Some more JavaScript
37
+
## Step 5: Async challenge
38
+
39
+
1. Rewrite the code below to Async:
40
+
41
+
```js
42
+
1.
43
+
44
+
let sum =calculateSum(2, 6);
45
+
console.log(sum);
46
+
47
+
2.
48
+
49
+
let results =$.getJSON('http://myapi.com');
50
+
showResults(results);
51
+
52
+
3.
53
+
54
+
let sum =calculateSum(2, 6);
55
+
if (sum >8) {
56
+
console.log('larger than 8');
57
+
}
58
+
59
+
4.
60
+
61
+
let data =$.getJSON('http://myapi.com');
62
+
data =data.map(function (x) { return x *8; });
63
+
64
+
writeDataToFile(data);
65
+
```
66
+
67
+
68
+
## Step 6: Some more JavaScript
34
69
35
70
_Deadline Saturday_
36
71
37
72
Make a website that fetches (= to get) data asynchronously.
38
73
39
-
1) Create a new website with external js file
74
+
1. Create a new website with external js file
40
75
41
-
2) Add a button (e.g. 'click me') that when clicked `console.logs` 'you clicked me!'
76
+
2. Add a button (e.g. 'click me') that when clicked `console.logs` 'you clicked me!'
42
77
43
-
3) Create a function that fetches from [The Github API](https://developer.github.com/v3/). For example from [this page] (https://api.github.com/orgs/HackYourFuture/repos) (the one we used last week). For help on this check this [SO post](https://stackoverflow.com/questions/247483/http-get-request-in-javascript)
78
+
3. Create a function that fetches from [The Github API](https://developer.github.com/v3/). For example from [this page] (https://api.github.com/orgs/HackYourFuture/repos) (the one we used last week). For help on this check this [SO post](https://stackoverflow.com/questions/247483/http-get-request-in-javascript)
44
79
45
-
4) Display the data that you get from the Github API on your web page.
80
+
4. Display the data that you get from the Github API on your web page.
46
81
47
-
5) Now link the two together: When you click the button -> get the data from the Github API and display it on your website
82
+
5. Now link the two together: When you click the button -> get the data from the Github API and display it on your website
48
83
49
-
6) Make all the repositories link their own page in Github. Use the value of the key: `name` to make this work (hint: Github urls always look like this https://api.github.com/repos/HackYourFuture/[repositoryName] where [repositoryName] would be replaced by the actual `name` of the repository, for example `CommandLine`). Make sure the link opens in a new tab.
84
+
6. Make all the repositories link their own page in Github. Use the value of the key: `name` to make this work (hint: Github urls always look like this https://api.github.com/repos/HackYourFuture/[repositoryName] where [repositoryName] would be replaced by the actual `name` of the repository, for example `CommandLine`). Make sure the link opens in a new tab.
You can see `CommandLine` in the URL. These are called "query parameters" and let us specify in detail what we want from the API. Play around with this. For example you can make two buttons that either get data for a specific repository, JavaScript or Node.js. Or go even more crazy and make users type in a search box 'JavaScript' and then send that to the API by changing the repository.
58
93
59
94
60
-
## Step 5: **Some freeCodeCamp challenges:**
95
+
## Step 7: **Some freeCodeCamp challenges:**
61
96
62
97
1.[Comparisons with the Logical And Operator](https://www.freecodecamp.com/challenges/comparisons-with-the-logical-and-operator)
0 commit comments