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/MAKEME.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -120,7 +120,7 @@ In the following tutorial you'll learn how to make a small web application that
120
120
121
121
-[Build an Issue Tracker](https://www.youtube.com/watch?v=NYq9J-Eur9U)
122
122
123
-
## **4. PROJECT: Random quote Generator**
123
+
## **4. PROJECT: Random Quote Generator**
124
124
125
125
> Every week ends with a project you have to build on your own. Instead of getting clear-cut instructions, you'll get a list of criteria that your project needs to measure up to.
Copy file name to clipboardExpand all lines: Week2/README.md
+16-6Lines changed: 16 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -30,11 +30,11 @@ This is also how JavaScript by default operates. Only one operation can happen a
30
30
31
31
### Asynchronous
32
32
33
-
Sometimes we want to do multiple things, without them being dependent on each other. Consider the following analogy:
33
+
Sometimes we want to do multiple things, without each action to be dependent on each other. Consider the following analogy:
34
34
35
-
> Wouter is feeling hungry so he decides to go to a restaurant. He arrives there and gets into the line to order food. After ordering he takes a seat and, while he waits, reads a book. Occassionally he looks around and sees different things happening: new people enter the restaurant, some people get their food served and others are just talking. After a short while Wouter's food arrives and it's time to dig in!
35
+
> Wouter is feeling hungry, so he decides to go to a restaurant. He arrives there and gets into the line to order food. After ordering he takes a seat and, while he waits, reads a book. Occassionally he looks around and sees different things happening: new people enter the restaurant, some people get their food served and others are just talking. After a short while Wouter's food arrives and it's time to dig in!
36
36
37
-
In this example Wouter reads a book, but that doesn't affect his meal from being prepared. Other
37
+
In this example Wouter reads a book, but that doesn't affect his meal from being prepared. [TO BE CONTINUED]
38
38
39
39
Take a look at the following diagram:
40
40
@@ -54,7 +54,7 @@ second();
54
54
55
55
In this example, only after `first()` has been executed will `second()` be executed. Only one thing happens at a time, and the next thing will ONLY happen after the previous thing has finished. This synchronous execution happens predictably and sequentially, without exception.
56
56
57
-
On the other hand we have
57
+
On the other hand we have[TO BE CONTINUED]
58
58
59
59
Executing each block of code (whether it's a line or a loop/function/etc.) after each other is called
60
60
@@ -66,9 +66,19 @@ Asynchronous execution avoids this bottleneck. You are essentially saying, “I
66
66
67
67
Imagine the following situation:
68
68
69
-
> It's 15.00 and you studying at home for an exam on the next day. Suddenly, your phone rings. You pick up and find it's your best friend! They ask if you'd like to hang out later. What do you do? On the one hand, you'd love to hang out have fun. On the other hand, you really should study some more. You don't know so tell your friend that you're going to call back later with your answer. You end the conversation and go back to studying. Maybe you take a short break and
69
+
> It's 15.00 and you're studying at home for an exam on the next day. Suddenly, your phone rings. You pick up and find it's your best friend! They ask if you'd like to hang out later. What do you do? On the one hand, you'd love to hang out have fun. On the other hand, you really should study some more. You don't know so you tell your friend that you're going to _call back_ later with your answer. You end the conversation and go back to studying. Maybe you take a break or have a snack as well. On the other line your friend hangs up the phone and continues along with their day: they go out grocery shopping, cleaning the house and cooking dinner. After finishing your studies you call your friend and makes plans to go out together.
70
70
71
-
By default JavaScript works **synchronously**, as we've learned in the previous section.
71
+
In this example there is one process: life. In technical terms you could call it the program. Life contains many things, but in this example it only contains two things: you and your friend. Let's call them mini programs, or `functions`. The function called "You" does various things: studying,
72
+
73
+
This example illustrates the concept of **asynchronicity**: there are multiple processes happening simultaneously, without any single thing being dependent upon another thing. Your friend is not waiting by the phone until you have the answer. Or in technical terms: until the callback (which is you) has the return value (the asnwer to your friend's request to hang out).
74
+
75
+
As we've learned in the previous section, by default JavaScript works **synchronously**. In short this means that only one command gets executed (and finishes) until the next command gets executed.
76
+
77
+
Take this insight to heart: **Synchronicity is the process, callbacks are the implementation**. Let's clarify that:
78
+
79
+
- Saying that the proces is synchronous, is saying that there can only be an execution of commands in a single sequence. But this process can be changed to be asynchronous, which means that the process can handle
80
+
81
+
to initiate that process change from synchronous to asynchronous.
72
82
73
83
This is why callbacks are important: it allows us to introduce asynchronicity in the control flow of a program.
The function should remove duplicate letters. So the result should be:
27
50
28
-
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).
51
+
```js
52
+
letters === ['a', 'b', 'c', 'd', 'e', 'f'];
53
+
```
29
54
30
55
**Exercise 3: Guess the output**
31
56
@@ -80,39 +105,16 @@ Now spreading the soya magarine
80
105
Spreading jam
81
106
```
82
107
83
-
**Exercise 5**
108
+
**Exercise 5: The lottery machine**
84
109
85
-
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:
110
+
Don't you just love the thrill of the lottery? What if I told you we can make our own lottery machine? Let's get started!
86
111
87
-
```js
88
-
functiondoIt() {
89
-
console.log('I am done');
90
-
}
91
-
setTimeout(doIt, 5000);
92
-
```
93
-
94
-
> If you run the above code it will wait 5 seconds and then print `I am done`. Please read something about setTimeout on MDN. The first argument to the `setTimeout` call is the callback (`doIt`).
95
-
96
-
**2.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.
97
-
98
-
```js
99
-
functionfoo(func) {
100
-
// What to do here?
101
-
}
102
-
103
-
functionbar() {
104
-
console.log('Hello, I am bar!');
105
-
}
106
-
107
-
foo(bar);
108
-
```
109
-
110
-
**2.2** You must write a function that takes 4 arguments.
112
+
Write a function that takes 4 arguments.
111
113
112
114
- A start value
113
115
- An end value
114
-
- A callback to call if the number is divisible by 3
115
-
- A callback to use if the number is divisible by 5
116
+
- A callback that executes if the number is divisible by 3
117
+
- A callback that executes if the number is divisible by 5
116
118
117
119
The function should first generate an array containing values from start value to end value (inclusive).
// please make sure you see why these calls are made before you start coding
137
138
```
138
139
140
+
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:
141
+
142
+
```js
143
+
functiondoIt() {
144
+
console.log('I am done');
145
+
}
146
+
setTimeout(doIt, 5000);
147
+
```
148
+
149
+
**2.2**
150
+
139
151
> Note: The following assignments include some problems from _freeCodeCamp_. Note that some _freeCodeCamp_ examples still mention `var`. However you can safely replace them with `let` and `const` as appropriate.
Copy file name to clipboardExpand all lines: Week3/README.md
+23-3Lines changed: 23 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,19 @@ These are the topics for week 3:
18
18
19
19
On of the central concepts in programming is the idea of `context`: the meaning of any particular thing is only determined in relation to its direct surroundings. Let's take language for example. If I say the following sentence:
20
20
21
-
> asdas
21
+
> I never said she stole my money.
22
22
23
-
Reading this it's not obvious how to interpret what's said. It depends on `context` for me to know how to look at it correctly.
23
+
Reading this it's not obvious how to interpret what the situation is about. Depending on the emphasis of the words it could mean any of the following:
24
24
25
-
In JavaScript, scope refers to the current context of your code.
25
+
-_I_ never said she stole my money.
26
+
- I _never_ said she stole my money.
27
+
- I never _said_ she stole my money.
28
+
- I never said _she_ stole my money.
29
+
- I never said she _stole_ my money.
30
+
- I never said she stole _my_ money.
31
+
- I never said she stole my _money_.
32
+
33
+
It depends on `context` for me to know what really happened. In programming, the term `scope` refers to the relevant variables that are involved in
26
34
27
35
### Global vs. local (function and block)
28
36
@@ -31,6 +39,15 @@ In JavaScript, scope refers to the current context of your code.
31
39
32
40
### Const and let
33
41
42
+
Quick refresher: Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.
43
+
44
+
In JavaScript we define them using the keyword `var`:
45
+
46
+
```js
47
+
var
48
+
49
+
```
50
+
34
51
## 2. Hoisting
35
52
36
53
If you look up the term "hoisting" in any dictionary, you'll find something like this:
@@ -55,10 +72,13 @@ Hoisting happens during `compile-time`.
55
72
56
73
## 3. Closures
57
74
75
+
Simply put, a closure is a function that is defined inside another function.
76
+
58
77
For further study please check the following resources:
59
78
60
79
-[The Ultimate Guide to Execution Contexts, Hoisting, Scoping and Closures in JavaScript](https://www.youtube.com/watch?v=Nt-qa_LlUH0)
0 commit comments