Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe44811

Browse files
author
Noer Paanakker
committed
finished makeme w2, added test
1 parent 2fc29dc commit fe44811

File tree

6 files changed

+158
-45
lines changed

6 files changed

+158
-45
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ If you have any questions or if something is not entirely clear ¯\\\_(ツ)\_/¯
3939
| 1. | Document-Object Model (DOM), DOM manipulation | [Reading W1](/Week1/README.md) | [Homework W1](/Week1/MAKEME.md) | [Lesson Plan W1](/Week1/LESSONPLAN.md) |
4040
| 2. | Synchronous vs. asynchronous, Event Loop, Callbacks, Array Functions | [Reading W2](/Week2/README.md) | [Homework W2](/Week2/MAKEME.md) | [Lesson Plan W2](/Week1/LESSONPLAN.md) |
4141
| 3. | Scope, Hoisting, Closures, Thinking like a programmer II | [Reading W3](/Week3/README.md) | [Homework W3](/Week3/MAKEME.md) | [Lesson Plan W3](/Week1/LESSONPLAN.md) |
42-
43-
## Test
44-
45-
At the end of this module you'll be doing a formative test. It will be done on **paper** and will consist of **4 exercises** that will test your JavaScript1 and JavaScript2 knowledge.
46-
47-
Why on paper? Fundamental understanding should become intuitive. Only after having learned and mastered a concept deeply will you be able to use it creatively. If you rely too much on others, on Google or your code editor to do your thinking you'll make it very hard to cultivate the habit to think for yourself.
42+
| 4. | Test | [Details](/test/README.md) | - | - |
4843

4944
## Finished?
5045

Week2/MAKEME.md

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ console.log(doubleEvenNumbers(myNumbers)); // Logs "[4, 8]" to the console
3838

3939
The `doubleEvenNumbers` function returns only the even numbers in the array `myNumbers` and doubles them. Like you've learned in the [README](README.md), this block of code isn't easy to decipher.
4040

41-
Let's rewrite it. Using the `map` and `filter` functions, rewrite the `doubleEvenNumbers` function.
41+
Let's rewrite it.
42+
43+
- Using the `map` and `filter` functions, rewrite the `doubleEvenNumbers` function.
4244

4345
**Exercise 2: What's your Monday worth?**
4446

@@ -65,23 +67,65 @@ const mondayTasks = [
6567
];
6668
```
6769

68-
Write a program that computes how much Maartje has earned by completing these tasks, using `map` and `filter`.
70+
Let's assume your hourly rate is €25. How much would you earn on that day?
6971

70-
For the 'summing part' you can try your luck with `reduce`; alternatively, you may use `forEach` or a `for` loop.
72+
- Write a program that computes that:
73+
- Use the `map` array function to take out the duration time for each task.
74+
- Multiply each duration by a per-hour rate for billing and sum it all up.
75+
- Output a formatted Euro amount, rounded to Euro cents, e.g: `€11.34`.
76+
- Make sure the program can be used on any array of objects that contain a `duration` property with a number value
7177

72-
Follow these steps. Each step should build on the result of the previous step.
78+
**Exercise 3: Lemon allergy**
7379

74-
- Map the tasks to durations in hours.
75-
- Filter out everything that took less than two hours (i.e., remove from the collection)
76-
- Multiply the each duration by a per-hour rate for billing (use €20/hour) and sum it all up.
77-
- Output a formatted Euro amount, rounded to Euro cents, e.g: `€11.34`.
78-
- Choose variable and parameters names that most accurately describe their contents or purpose. When naming an array, use a plural form, e.g. `durations`. For a single item, use a singular form, e.g. `duration`.
80+
Your mom bought you a basket of fruit, because you're doing so well in HackYourFuture. How sweet of her!
81+
82+
```js
83+
const fruitBasket = ['Apple', 'Lemon', 'Grapefruit', 'Lemon', 'Banana', 'Watermelon', 'Lemon'];
84+
```
85+
86+
However, she forgot that you are allergic to lemons! Let's quickly dispose of them before you get an attack.
87+
88+
- Write a function
89+
- Use the `filter` array function to take out the lemons
90+
- Output a string that says: "My mom bought me a fruit basket, containing [array of fruits] !"
7991

80-
**Exercise 3**
92+
**Exercise 4: Collective age**
8193

82-
**Exercise 4**
94+
Have you ever wondered how old the HackYourFuture team members are? Or better yet: what the collective age is? Let's find out!
95+
96+
```js
97+
const hackYourFutureMembers = [
98+
{ name: 'Wouter', age: 33 },
99+
{ name: 'Federico', age: 32 },
100+
{ name: 'Noer', age: 27 },
101+
{ name: 'Tjebbe', age: 22 },
102+
];
103+
```
104+
105+
- Write a program that calculates the combined age of every member
106+
- Make use of the `map` function to get the ages
107+
- It should contain a function that takes a callback
108+
- The callback adds all the ages together and returns the number
109+
- The main function should log the string "The collective age of the HYF team is: [number]" to the console, and afterwards return the number
110+
111+
**Exercise 5: My favorite hobbies**
112+
113+
I've got a couple of hobbies that I want to showcase in a webpage.
114+
115+
```js
116+
const myHobbies = [
117+
'Meditation',
118+
'Reading',
119+
'Programming',
120+
'Hanging out with friends',
121+
'Going to the gym',
122+
];
123+
```
83124

84-
**Exercise 5 **
125+
- Write a program that outputs each of these inside an HTML file
126+
- Create an HTML and JavaScript file, link them together
127+
- Use the `map` and/or `forEach` function to put each hobby into a <li>
128+
- Output the list items in an unordered list
85129

86130
## **3. Code along**
87131

Week2/README.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ These are the topics for week 2:
77
1. Synchronous vs. asynchronous
88
- Synchronous
99
- Asynchronous
10-
- Why do we need asynchronicity?
1110
2. Introducing asynchronicity using callbacks
1211
- Higher order functions
1312
- Functions as arguments to other functions
@@ -36,39 +35,52 @@ As you can see, each action is executed in a synchronous manner. This is to say:
3635

3736
### Asynchronous
3837

39-
Sometimes we want to do multiple things at the same time, without each action to be dependent on each other. Consider the following scenario:
38+
Sometimes we want to do multiple things at the same time, without each action to be dependent on each other. Asynchronous execution avoids this bottleneck. You are essentially saying, “I know this function call is going to take a great deal of time, but my program doesn’t want to wait around while it executes.” Consider the following scenario:
4039

4140
> 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!
4241
4342
In this example Wouter reads a book, but that doesn't affect his meal from being prepared. While his meal is prepared there are other people walking around, eating or just talking with each other. In short: multiple things are happening simultaneously and every event is not dependent upon another.
4443

45-
This does not happen by default in JavaScript, and needs to be invoked. A way to do that is by using `callbacks`, which you'll be learning about later.
44+
This does not happen by default in JavaScript, and needs to be invoked. A way to do that is by using `callbacks`, which you'll be learning about in the next section.
4645

47-
## Why do we need asynchronicity?
46+
## 2. Introducing asynchronicity using callbacks
4847

49-
In programming
48+
Before we dive into what a `callback` is we have to understand a little about `higher order functions`.
5049

51-
This method of execution can have undesirable consequences. Suppose a function is called to start a time consuming process. What if you want to stop the lengthy process? With synchronous execution, your program is “stuck,” waiting for the process to end, with no way out.
50+
### Higher order functions
5251

53-
Asynchronous execution avoids this bottleneck. You are essentially saying, “I know this function call is going to take a great deal of time, but my program doesn’t want to wait around while it executes.”
52+
Let's start with a simple, practical definition: a higher order function is any function that can take another function as an argument or returns a function.
5453

55-
## 2. Introducing asynchronicity using callbacks
54+
```js
55+
// Example 1
56+
function higherOrderFunction(anotherFunction) {
57+
anotherFunction();
58+
return;
59+
}
5660

57-
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, taking a break and having a snack.
61+
// Example 2
62+
function anotherHigherOrderFunction() {
63+
return function() {
64+
return;
65+
};
66+
}
67+
```
5868

59-
This example illustrates the concept of **asynchronicity**: there are multiple processes happening simultaneously, without any single thing being dependent upon another. 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).
69+
Why do we need them? A higher order function integrates multiple functions, which each have a singular operational purpose. This will allow us to reuse code much more than if we had to write everything out.
6070

61-
### Higher order functions
71+
> Higher order functions are a core concept within a programming paradigm called "functional programming". It's not relevant at all for you to know or care about this, but it's important to be exposed to it.
6272
6373
### Functions as arguments to other functions
6474

6575
Imagine the following situation:
6676

6777
> 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.
6878
69-
**This is why callbacks are important: it allows us to introduce asynchronicity in the control flow of a program.**
79+
This example illustrates the concept of **asynchronicity**: there are multiple processes happening simultaneously, without any single thing being dependent upon another. 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 answer to your friend's request to hang out).
7080

71-
A concrete example for why this might be useful is when you want to [TBC!!!]
81+
This is the utility of `callbacks`: they allow us to introduce asynchronicity into the control flow of an application.
82+
83+
Let's put this into the context of a webpage.
7284

7385
Study the following resources to learn more about the importance of callbacks:
7486

@@ -85,11 +97,9 @@ There are different ways of dealing with arrays. The most common way is by using
8597
1. The first disadvantage is that using loops requires us to write custom logic for each use case. This can lead to repeated code, which we always want to [avoid](https://www.youtube.com/watch?v=IGH4-ZhfVDk)
8698
2. The second disadvantage is that a loop isn't descriptive about what it intends to do. If another developer reads that code it wouldn't be obvious what it would do, without spending time on it to decipher it
8799

88-
There are certain functions, `array functions`, that aim to solve these two problems simultaneously.
89-
90-
Let's take an array function as an example: the `map()` function. It takes a function as an argument, and executes that unto each index position of the array, returning at the end a new array with all the "mapped" values.
100+
There are certain functions, `array functions`, that aim to solve these two problems simultaneously. Array functions are higher order functions, because they take a function as an argument.
91101

92-
> Array functions are in general higher order functions, meaning they're functions that take a function as an argument.
102+
Let's take an example: the `map()` function. It takes a function as an argument, and executes that unto each index position of the array, returning at the end a new array with all the "mapped" values.
93103

94104
Take a look at the following code snippet to see it in action:
95105

@@ -141,7 +151,7 @@ In simple terms, the `Event Loop` is a mechanism that operates in the browser. I
141151
1. Heap. This is where the browser assigns space in memory to each process
142152
2. Call Stack. This is the amount of JavaScript commands (read: function calls and events) that need to be executed
143153
3. Web APIs. These are objects (like the document) and functions (like XMLHttpRequest) that can be used within the JavaScript commands found in the Call Stack
144-
4. Callback Queue. This is the
154+
4. Callback Queue. This is the "waiting line" [ajksdbjkasbdjkasbnjkdbajksbdkj]
145155

146156
To see it in action check out the following resources:
147157

Week3/MAKEME.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
1. Practice the concepts
66
2. JavaScript exercises
77
3. Code along
8-
4. PROJECT:
8+
4. PROJECT: The Tip Calculator
99

1010
## **1. Practice the concepts**
1111

1212
Let's get familiar with basic Javascript concepts, with interactive exercises! Check out the following resources:
1313

14-
- [Introduction to JavaScript: Scope (Codecademy)](https://www.codecademy.com/courses/introduction-to-javascript/lessons/scope/exercises/scope)
14+
- [Introduction to JavaScript: Scope](https://www.codecademy.com/courses/introduction-to-javascript/lessons/scope/exercises/scope)
1515

1616
## **2. JavaScript exercises**
1717

Week3/README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ These are the topics for week 3:
1212
- When does it happen
1313
- Why do we need to know it?
1414
3. Closures
15+
- Execution context
16+
- Defining a function within a function
1517
4. Thinking like a programmer II
1618

1719
## 1. Scope
1820

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:
21+
One 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:
2022

2123
> I never said she stole my money.
2224
@@ -32,30 +34,37 @@ Reading this it's not obvious how to interpret what the situation is about. Depe
3234

3335
It depends on `context` for me to know what really happened.
3436

35-
Let's draw the line to programming. Within any program there is a lot happening. But not everything is related to each other; some functions don't depend on other functions or variables
37+
Let's draw the line to programming. Simply put, just like context gives meaning to a word, `scope` gives meaning to a variable/object.
3638

37-
`scope` has to do with "where we can access variables from"
39+
The meaning is defined by whether or not the variable is accessible or not. If the variable is not within the scope
3840

3941
For further research, check out the following:
4042

4143
- [Variable Scope & Context](https://www.youtube.com/watch?v=WPcW83BMT3Y)
4244

4345
### Global vs. local (function and block)
4446

47+
In any given application, there is usually one global scope. But there can be many local scopes
48+
4549
- [Understanding Scope in JavaScript](https://www.youtube.com/watch?v=SBjf9-WpLac)
4650
- [Everything you wanted to know about JavaScript scope](https://ultimatecourses.com/blog/everything-you-wanted-to-know-about-javascript-scope)
4751

4852
### Const and let
4953

50-
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.
54+
> 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.
5155
52-
In JavaScript we define them using the keyword `var`:
56+
In JavaScript we used to define variables using the keyword `var`:
5357

5458
```js
55-
var
56-
59+
var myName = 'Mohammed';
5760
```
5861

62+
However
63+
64+
In programming, we generally want to keep things as simple as they can be. We even have a name for that: [KISS](https://thevaluable.dev/kiss-principle-explained/) (Keep it Simple, Stupid!)
65+
66+
- [How let and const are scoped in JavaScript](https://wesbos.com/javascript-scoping/)
67+
5968
## 2. Hoisting
6069

6170
If you look up the term "hoisting" in any dictionary, you'll find something like this:
@@ -82,6 +91,14 @@ Hoisting happens during `compile-time`.
8291

8392
Simply put, a closure is a function that is defined inside another function.
8493

94+
### Execution context
95+
96+
In your programming journey you'll learn that many concepts overlap one another.
97+
98+
An execution context is
99+
100+
### Defining a function within a function
101+
85102
For further study please check the following resources:
86103

87104
- [The Ultimate Guide to Execution Contexts, Hoisting, Scoping and Closures in JavaScript](https://www.youtube.com/watch?v=Nt-qa_LlUH0)

test/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# JavaScript1 and JavaScript2 Test
2+
3+
At the end of this module you’ll be doing a comprehension test on paper. Why on paper? Fundamental understanding should become intuitive. Only after having learned and mastered a concept deeply will you be able to use it creatively. If you rely too much on others, on Google or your code editor to do your thinking you'll make it very hard to cultivate the habit to think for yourself.
4+
5+
### Concepts
6+
7+
It will be about the most important JavaScript concepts you’ve learned about so far (JavaScript1 and JavaScript2). Here’s a list of all of them:
8+
9+
- Variables (const and let)
10+
- Data types (strings, numbers, arrays, objects, booleans)
11+
- Conditional statements (if/switch statement)
12+
- Loops
13+
- Regular and arrow functions
14+
- How to use JavaScript to do basic DOM manipulations (add, modify and remove DOM elements)
15+
- Code commenting
16+
- Scope
17+
- Array functions (map and filter)
18+
- Callbacks
19+
- Hoisting
20+
21+
### Purpose of the test
22+
23+
The purpose of this exam is to test your comprehension of JavaScript1 and JavaScript2 concepts.
24+
25+
- The goal for us is to know how solid your knowledge is and if you need any extra assistance throughout the program.
26+
- The goal for you is to test how well enough you master the material so far.
27+
28+
Therefore, **you won’t be graded**. Like the homework you will get feedback and are expected to improve upon your weak points.
29+
30+
### Preparation
31+
32+
Here's general advice on how to optimally prepare:
33+
34+
- Make a list of every concept you currently don’t understand at all.
35+
- Find out 2 things about each concept: (1) how does the basic structure look and (2) what is the most common use case.
36+
- Ask questions through Slack to your teachers and/or your classmates
37+
- Practice coding WITHOUT Google.
38+
- Practice for understanding (why something is the case), NOT just for repetition’s sake (and hoping ‘you will understand it one day’).
39+
- Stay calm, always
40+
41+
### Practical information
42+
43+
- The test will last about an hour
44+
- It will be done on paper so please **bring a pencil and eraser**.
45+
- There will be 4 questions, 2 for each module
46+
47+
Tip: if any of you need additional support, now is the moment to let us know as we can pair you up with someone to answer any questions you may have up until this point.

0 commit comments

Comments
 (0)