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

Skip to content

Commit 39eb369

Browse files
committed
Updated so there is ModernJS and some challenges at the end
1 parent 2612abf commit 39eb369

8 files changed

+113
-5
lines changed

Week3/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ These are the topics for week 3:
66

77
1. [Functions](https://study.hackyourfuture.net/#/javascript/functions)
88
2. [Scope](https://study.hackyourfuture.net/#/javascript/scope)
9-
3. [DRY Principle](https://study.hackyourfuture.net/#/programming/dont-repeat-yourself)
9+
3. [Modern JS](https://study.hackyourfuture.net/#/javascript/modern-js)
1010

1111
## Week goals
12-
This week is the last week of explaining all the basic building blocks that JavaScript offers for you to work with. The last one is called functions, read all about them [here](https://study.hackyourfuture.net/#/javascript/functions). Functions bring along with them a concept called the scope that you may have encountered a bit last week but we want to explicitely explain now. Read about scope [here](https://study.hackyourfuture.net/#/javascript/scope).
12+
This week is the last week of explaining all the basic building blocks that JavaScript offers for you to work with. The last one is called functions, read all about them [here](https://study.hackyourfuture.net/#/javascript/functions). Functions bring along with them a concept called the scope that you may have encountered a bit last week but we want to explicitely explain now. Read about scope [here](https://study.hackyourfuture.net/#/javascript/scope).
1313

1414
These things will take the power of what you can do to another level, as it allows you to group a certain set of lines of code into a single 'action' to take. Making it reusable in other places as well helping you organise your code, which will help a lot when you start writing more and more code. This also brings us to another principle of programming that we want you to get into the habit of doing, that is the DRY (Don't Repeat Yourself) principle. Read about that [here](https://study.hackyourfuture.net/#/programming/dont-repeat-yourself)!
1515

16-
It is time to combine everything you have learned and start practicing them vigorously. Have a look at the exercises [here](./MAKEME.md) and try to make as many of them as you can. This week there will be homework to do and hand in, so don't forget to do that!
16+
Now that you have learned all the basic blocks it is time to tell you about the different versions of JavaScript. JavaScript has been evolving over its lifetime and certain syntax has been added. Have a look in your study book at the topic of what is called 'Modern JS' [here](https://study.hackyourfuture.net/#/javascript/modern-js). Throughout the curriculum we will be expecting you to use the modern syntax as that is most likely what you will be programming in. There is also a section on the history of JavaScript in there, you do not need to know this but we recommend it if you have some time to spare as it is very interesting.
1717

1818
## Finished?
1919

20-
Are you finished with going through the materials? Give yourself a pat on the back because you rock! When you feel ready to get practical, click [here](./MAKEME.md).
20+
Are you finished with going through the materials? Give yourself a pat on the back because you rock! It is time to combine everything you have learned and start practicing them vigorously. Have a look at the exercises [here](./MAKEME.md) and try to make as many of them as you can. This week there will be homework to do and hand in, so don't forget to do that! If you haven't set up the homework repository yet, have a look at your class repo.

Week4/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ These are the topics for week 4:
66

77
1. [Higher Order Functions](https://study.hackyourfuture.net/#/javascript/higher-order-functions)
88
- Array methods
9-
- Arrow functions
109
2. [Closures](https://study.hackyourfuture.net/#/javascript/closures)
1110
- Execution context
1211
- Why do we need closures?

Week4/challenges/1-sum-entries.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Credit to https://adventofcode.com/ for this exercise
3+
4+
In the list below you have an array of numbers. The goal is to find the two numbers that add up to 2020.
5+
6+
Once you have found those numbers, multiply the numbers and store the result of that in the result variable.
7+
*/
8+
9+
10+
const list = [1721, 979, 366, 299, 675, 1456];
11+
let result;
12+
13+
// Write your code here
14+
15+
16+
// TEST CODE, do not change
17+
console.assert(result === 514579, `The result is not correct, it is ${result}, but should be 514579`);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Credit to https://adventofcode.com/ for this exercise
3+
4+
In the list below you have an array of numbers. The goal is to find the three numbers that add up to 2020.
5+
6+
Once you have found those numbers, multiply the numbers and store the result of that in the result variable.
7+
*/
8+
9+
10+
const list = [1721, 979, 366, 299, 675, 1456];
11+
let result;
12+
13+
// Write your code here
14+
15+
16+
// TEST CODE, do not change
17+
console.assert(result === 241861950, `The result is not correct, it is ${result}, but should be 241861950`);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
/**
3+
* Credit to https://adventofcode.com/ for this exercise
4+
*
5+
* Each object in the passwordList gives a password policy and then the password.
6+
* The times field says the minimal and maximal amount of times the letter should be in the password. So 1-3 means at least 1 time, at most 3 times.
7+
* The letter field gives which letter should be counted
8+
* The password field gives the password
9+
*
10+
* In the list 2 passwords are valid, the middle one is not as there is no b in the password.
11+
*
12+
* We expect the output:
13+
*
14+
* 'abcde' is VALID, a is present 1 times and should have been present at least 1 and at most 3 times
15+
* 'cdefg' is INVALID, b is present 0 times and should have been present at least 1 and at most 3 times
16+
* 'ccccccccc' is VALID, c is present 9 times and should have been present at least 2 and at most 9 times
17+
*/
18+
19+
const passwordList = [
20+
{ times: '1-3', letter: 'a', password: 'abcde'},
21+
{ times: '1-3', letter: 'b', password: 'cdefg'},
22+
{ times: '2-9', letter: 'c', password: 'ccccccccc'}
23+
];
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const list = [1721, 979, 366, 299, 675, 1456];
2+
let result;
3+
4+
list.forEach((item, idx) => {
5+
// We use a for loop here instead of forEach so we only compare the numbers after the current item in the list
6+
for (let i = idx + 1; i < list.length; i++) {
7+
if ((item + list[i]) === 2020) {
8+
result = item * list[i];
9+
}
10+
}
11+
});
12+
13+
// TEST CODE, do not change
14+
console.assert(result === 514579, `The result is not correct, it is ${result}, but should be 514579`);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const list = [1721, 979, 366, 299, 675, 1456];
2+
let result;
3+
4+
list.forEach((item, idx) => {
5+
// We use a for loop here instead of forEach so we only compare the numbers after the current item in the list
6+
for (let i = idx + 1; i < list.length; i++) {
7+
for (let j = i + 1; j < list.length; j++) {
8+
if ((item + list[i] + list[j]) === 2020) {
9+
result = item * list[i] * list[j];
10+
}
11+
}
12+
}
13+
});
14+
15+
// TEST CODE, do not change
16+
console.assert(result === 241861950, `The result is not correct, it is ${result}, but should be 241861950`);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const passwordList = [
2+
{ times: '1-3', letter: 'a', password: 'abcde'},
3+
{ times: '1-3', letter: 'b', password: 'cdefg'},
4+
{ times: '2-9', letter: 'c', password: 'ccccccccc'}
5+
];
6+
7+
passwordList.forEach(item => {
8+
// convert the element password to array
9+
const { password, times, letter } = item;
10+
11+
const onlyLetterArray = Array.from(password).filter(character => character === letter);
12+
const amountOfInstancesOfLetter = onlyLetterArray.length;
13+
const minimumAmount = parseInt(times.slice(0, 1));
14+
const maximumAmount = parseInt(times.slice(2));
15+
16+
if (amountOfInstancesOfLetter >= minimumAmount && amountOfInstancesOfLetter <= maximumAmount) {
17+
console.log(`${password} is VALID, ${letter} is present ${amountOfInstancesOfLetter} times and should have been present at least ${minimumAmount} and at most ${maximumAmount} times`);
18+
}
19+
else {
20+
console.log(`${password} is INVALID, ${letter} is present ${amountOfInstancesOfLetter} times and should have been present at least ${minimumAmount} and at most ${maximumAmount} times`);
21+
}
22+
});

0 commit comments

Comments
 (0)