├── .gitignore
├── .prettierrc.js
├── README.md
├── index.html
├── package-lock.json
├── package.json
└── src
├── 01-exercise
├── 01-exercise-setup.js
├── 01-exercise.html
└── 01-exercise.js
├── 02-exercise
├── 02-exercise-setup.js
├── 02-exercise.html
└── 02-exercise.js
├── 03-exercise
├── 03-exercise-setup.js
├── 03-exercise.html
└── 03-exercise.js
├── 04-exercise
├── 04-exercise-setup.js
├── 04-exercise.html
└── 04-exercise.js
├── 05-exercise
├── 05-exercise-setup.js
├── 05-exercise.html
└── 05-exercise.js
├── 06-exercise
├── 06-exercise-setup.js
├── 06-exercise.html
└── 06-exercise.js
├── 07-exercise
├── 07-exercise-setup.js
├── 07-exercise.html
└── 07-exercise.js
├── 08-exercise
├── 08-exercise-setup.js
├── 08-exercise.html
└── 08-exercise.js
├── 09-exercise
├── 09-exercise-setup.js
├── 09-exercise.html
└── 09-exercise.js
├── 10-exercise
├── 10-exercise-setup.js
├── 10-exercise.html
└── 10-exercise.js
├── 11-exercise
├── 11-exercise-setup.js
├── 11-exercise.html
└── 11-exercise.js
├── 12-exercise
├── 12-exercise-setup.js
├── 12-exercise.html
└── 12-exercise.js
├── 13-exercise
├── 13-exercise-setup.js
├── 13-exercise.html
└── 13-exercise.js
├── 14-exercise
├── 14-exercise-setup.js
├── 14-exercise.html
└── 14-exercise.js
├── 15-exercise
├── 15-exercise-setup.js
├── 15-exercise.html
└── 15-exercise.js
├── 16-exercise
├── 16-exercise-fns.js
├── 16-exercise-setup.js
├── 16-exercise.html
└── 16-exercise.js
├── 17-exercise
├── 17-exercise-setup.js
├── 17-exercise.html
└── 17-exercise.js
├── 18-exercise
├── 18-exercise-setup.js
├── 18-exercise.html
└── 18-exercise.js
├── 19-exercise
├── 19-exercise-setup.js
├── 19-exercise.html
└── 19-exercise.js
├── 20-exercise
├── 20-exercise-setup.js
├── 20-exercise.html
└── 20-exercise.js
├── 21-exercise
├── 21-exercise-setup.js
├── 21-exercise.html
└── 21-exercise.js
├── __tests__
├── 01-exercise.test.js
├── 02-exercise.test.js
├── 03-exercise.test.js
├── 04-exercise.test.js
├── 05-exercise.test.js
├── 06-exercise.test.js
├── 07-exercise.test.js
├── 08-exercise.test.js
├── 09-exercise.test.js
├── 10-exercise.test.js
├── 11-exercise.test.js
├── 12-exercise.test.js
├── 13-exercise.test.js
├── 14-exercise.test.js
├── 15-exercise.test.js
├── 16-exercise.test.js
├── 17-exercise.test.js
├── 18-exercise.test.js
├── 19-exercise.test.js
├── 20-exercise.test.js
└── 21-exercise.test.js
├── styles.css
└── utils
└── utils.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | .parcel-cache
4 | dist
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | tabWidth: 4
3 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | `#es6` `#assembler-institute` `#master-in-software-engineering`
2 |
3 | # Assembler Institute: ES6 Workshop Exercises
4 |
5 | ## Getting Started
6 |
7 | First, you will need to clone the repo:
8 |
9 | ```bash
10 | $ git clone https://github.com/assembler-institute/es6-and-beyond-exercises.git
11 | ```
12 |
13 | Then, you will have to install all the dependencies with npm:
14 |
15 | ```bash
16 | $ npm install
17 | ```
18 |
19 | ## Exercises
20 |
21 | Open the files in the `src/` folder and follow the instructions.
22 |
23 | ## Author
24 |
25 | [Dani Lucaci](https://github.com/danilucaci)
26 |
27 | ## License
28 |
29 | [MIT](https://choosealicense.com/licenses/mit/)
30 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Assembler School
5 |
6 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | ES6 Exercises
18 |
19 |
20 |
21 |
Exercises
22 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "es6-and-beyond",
3 | "version": "1.1.0",
4 | "description": "es6-and-beyond",
5 | "keywords": [],
6 | "author": "Dani Lucaci ",
7 | "license": "MIT",
8 | "main": "index.js",
9 | "scripts": {
10 | "start": "parcel index.html --open",
11 | "test": "jest --watchAll"
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "https://github.com/assembler-institute/es6-and-beyond-exercises.git"
16 | },
17 | "browserslist": [
18 | "since 2017-06"
19 | ],
20 | "dependencies": {
21 | "@babel/core": "7.17.8",
22 | "@babel/preset-env": "7.16.11",
23 | "@types/jest": "27.4.1",
24 | "babel-jest": "27.5.1",
25 | "jest": "27.5.1",
26 | "parcel": "2.4.0"
27 | },
28 | "devDependencies": {
29 | "@babel/eslint-parser": "7.17.0",
30 | "assert": "^2.0.0",
31 | "buffer": "^6.0.3",
32 | "eslint": "8.11.0",
33 | "jest-transform-stub": "2.0.0",
34 | "path-browserify": "^1.0.1",
35 | "process": "^0.11.10",
36 | "util": "^0.12.4"
37 | },
38 | "jest": {
39 | "testEnvironment": "jsdom",
40 | "transform": {
41 | ".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",
42 | "^.+\\.js$": "babel-jest"
43 | }
44 | },
45 | "babel": {
46 | "presets": [
47 | "@babel/preset-env"
48 | ]
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/01-exercise/01-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup01Exercise(exercise01) {
4 | if (isFunction(exercise01)) {
5 | exercise01();
6 | }
7 | }
8 |
9 | export default setup01Exercise;
10 |
--------------------------------------------------------------------------------
/src/01-exercise/01-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/01-exercise/01-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 01:
3 | *
4 | * Finish the code of the `exercise01` function
5 | * so that it:
6 | *
7 | * 1. Receives a parameter named `a` that has a default value of 1
8 | *
9 | * 2. Receives a parameter named `b` that has a default value of 1
10 | *
11 | * 3. Returns the multiplication of the `a` and `b` parameters
12 | *
13 | * The function should have default values for each parameter
14 | * so that if it is called without a value for each one of them
15 | * it picks up the default value.
16 | */
17 |
18 | // Finish the code of the function
19 | function exercise01(a = 1, b = 1) {
20 | return a * b;
21 | }
22 |
23 | // Don’t change the code bellow this line
24 | import setup01Exercise from "./01-exercise-setup";
25 |
26 | if (process.env.NODE_ENV !== "test") {
27 | setup01Exercise(() => console.log(exercise01()));
28 | setup01Exercise(() => console.log(exercise01(5)));
29 | setup01Exercise(() => console.log(exercise01(undefined, 2)));
30 | }
31 |
32 | export default exercise01;
33 |
--------------------------------------------------------------------------------
/src/02-exercise/02-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup02Exercise(exercise02) {
4 | if (isFunction(exercise02)) {
5 | exercise02();
6 | }
7 | }
8 |
9 | export default setup02Exercise;
10 |
--------------------------------------------------------------------------------
/src/02-exercise/02-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/02-exercise/02-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 02:
3 | *
4 | * Finish the code of the `exercise02` function.
5 | *
6 | * The function will receive an object as a parameter with
7 | * the following shape:
8 | *
9 | * {
10 | * firstName: "Ana",
11 | * lastName: "Marks",
12 | * }
13 | *
14 | * 1. The function should destructure the keys from the parameter
15 | * in the function definition so that it captures the
16 | * `firstName` and `lastName` keys from the object
17 | *
18 | * @example
19 | * function hello({ message }) { ... }
20 | *
21 | * 2. Both destructured keys should have a default value of:
22 | * firstName = "Default firstName"
23 | * lastName = "Default lastName"
24 | *
25 | * @example
26 | * function hello({ message = "default message" }) { ... }
27 | *
28 | * 3. Returns the concatenation of the `firstName` and `lastName` variables
29 | *
30 | * @example
31 | *
32 | * {
33 | * firstName: "Ana",
34 | * lastName: "Marks",
35 | * }
36 | *
37 | * The `firstName` and `lastName` should be concatenated
38 | * with the following strings:
39 | *
40 | * => `Hello I am Ana Marks`
41 | */
42 |
43 | // Finish the code of the function
44 | function exercise02({firstName = "Default firstName", lastName = "Default lastName"}) {
45 |
46 | const hello = `Hello I am ${firstName} ${lastName}`;
47 |
48 | return hello;
49 |
50 | }
51 |
52 | // Don’t change the code bellow this line
53 | import setup02Exercise from "./02-exercise-setup";
54 |
55 | if (process.env.NODE_ENV !== "test") {
56 | setup02Exercise(() =>
57 | console.log(
58 | exercise02({
59 | firstName: "John",
60 | lastName: "Second",
61 | })
62 | )
63 | );
64 | setup02Exercise(() => console.log(exercise02({})));
65 | }
66 |
67 | export default exercise02;
68 |
--------------------------------------------------------------------------------
/src/03-exercise/03-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup03Exercise(exercise03) {
4 | if (isFunction(exercise03)) {
5 | exercise03();
6 | }
7 | }
8 |
9 | export default setup03Exercise;
10 |
--------------------------------------------------------------------------------
/src/03-exercise/03-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/03-exercise/03-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 03:
3 | *
4 | * Finish the code of the `exercise03` function.
5 | *
6 | * The function will be called with several parameters with
7 | * the following shape:
8 | *
9 | * exercise03("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
10 | *
11 | * 1. The function should capture the first 2 elements and
12 | * all the other ones in a an array using the `...rest` syntax
13 | * which will create an array with all the remaining parameters
14 | *
15 | * @example
16 | * function hello(a, b, ...rest) { ... }
17 | *
18 | * 2. Return the array of the remaining parameters
19 | *
20 | * @example
21 | *
22 | * exercise03(1, 2, 3, 4, 5, 6)
23 | *
24 | * => [3, 4, 5, 6]
25 | */
26 |
27 | // Finish the code of the function
28 | const exercise03 = (a, b, ...days) => {
29 |
30 | const arr = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
31 |
32 | return arr;
33 |
34 | };
35 |
36 | // Don’t change the code bellow this line
37 | import setup03Exercise from "./03-exercise-setup";
38 |
39 | if (process.env.NODE_ENV !== "test") {
40 | setup03Exercise(() =>
41 | console.log(
42 | exercise03("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
43 | )
44 | );
45 | }
46 |
47 | export default exercise03;
48 |
--------------------------------------------------------------------------------
/src/04-exercise/04-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup04Exercise(exercise04) {
4 | if (isFunction(exercise04)) {
5 | exercise04();
6 | }
7 | }
8 |
9 | export default setup04Exercise;
10 |
--------------------------------------------------------------------------------
/src/04-exercise/04-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/04-exercise/04-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 04:
3 | *
4 | * Finish the code of the `exercise04` function.
5 | *
6 | * The function will receive an array as a parameter with
7 | * the following shape:
8 | *
9 | * ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
10 | *
11 | * 1. The function should destructure the first 3 elements of the array
12 | *
13 | * @example
14 | * function hello([a, b, c, d, e]) { ... }
15 | *
16 | * 2. Return the second element: index [1]
17 | */
18 |
19 | // Finish the code of the function
20 | function exercise04([a, b, c]) {
21 | return b;
22 | }
23 |
24 | exercise04(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]);
25 |
26 | // Don’t change the code bellow this line
27 | import setup04Exercise from "./04-exercise-setup";
28 |
29 | if (process.env.NODE_ENV !== "test") {
30 | setup04Exercise(() =>
31 | console.log(
32 | exercise04(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"])
33 | )
34 | );
35 | }
36 |
37 | export default exercise04;
38 |
--------------------------------------------------------------------------------
/src/05-exercise/05-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup05Exercise(exercise05) {
4 | if (isFunction(exercise05)) {
5 | exercise05();
6 | }
7 | }
8 |
9 | export default setup05Exercise;
10 |
--------------------------------------------------------------------------------
/src/05-exercise/05-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/05-exercise/05-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 05:
3 | *
4 | * Finish the code of the `exercise05` function.
5 | *
6 | * The function will receive an array as a parameter with
7 | * the following shape:
8 | *
9 | * ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
10 | * ["Monday", undefined, "Wednesday", "Thursday", "Friday"]
11 | *
12 | * 1. The function should destructure the first 3 elements of the array
13 | *
14 | * @example
15 | * function hello([a, b, c, d, e]) { ... }
16 | *
17 | * 2. The function should add a default value of "DEFAULT"
18 | * to the second destructured element
19 | *
20 | * @example
21 | * function hello([a, b, c, d = "SOME VALUE"]) { ... }
22 | *
23 | * 3. Return the second element: index [1]
24 | */
25 |
26 | // Finish the code of the function
27 | function exercise05([a, b = "DEFAULT", c]) {
28 |
29 | return b;
30 |
31 | }
32 |
33 | exercise05(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]);
34 |
35 | // Don’t change the code bellow this line
36 | import setup05Exercise from "./05-exercise-setup";
37 |
38 | if (process.env.NODE_ENV !== "test") {
39 | setup05Exercise(() =>
40 | console.log(
41 | exercise05(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"])
42 | )
43 | );
44 | setup05Exercise(() =>
45 | console.log(
46 | exercise05(["Monday", undefined, "Wednesday", "Thursday", "Friday"])
47 | )
48 | );
49 | }
50 |
51 | export default exercise05;
52 |
--------------------------------------------------------------------------------
/src/06-exercise/06-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup06Exercise(exercise06) {
4 | if (isFunction(exercise06)) {
5 | exercise06();
6 | }
7 | }
8 |
9 | export default setup06Exercise;
10 |
--------------------------------------------------------------------------------
/src/06-exercise/06-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/06-exercise/06-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 06:
3 | *
4 | * Finish the code of the `exercise06` function so that it:
5 | *
6 | * 1. Destructures the first 2 keys of the `user` object
7 | * and gathers all the other keys in an object
8 | * using destructuring.
9 | *
10 | * @example
11 | * const data = { a: 1, b: 2, c: 3, d: 4};
12 | *
13 | * const {a, b, ...rest} = data;
14 | * => rest = { c: 3, d: 4 }
15 | *
16 | * 2. Return the object with the remaining keys
17 | */
18 |
19 | // Finish the code of the function
20 | function exercise06() {
21 | const user = {
22 | firstName: "John",
23 | lastName: "Marks",
24 | age: 33,
25 | jobTitle: "Student",
26 | company: "Assembler School",
27 | averageGrade: 6.6,
28 | };
29 |
30 | const {firstName, lastName, ...rest} = user;
31 | return rest;
32 | }
33 |
34 | // Don’t change the code bellow this line
35 | import setup06Exercise from "./06-exercise-setup";
36 |
37 | if (process.env.NODE_ENV !== "test") {
38 | setup06Exercise(() => console.log(exercise06()));
39 | }
40 |
41 | export default exercise06;
42 |
--------------------------------------------------------------------------------
/src/07-exercise/07-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup07Exercise(exercise07) {
4 | if (isFunction(exercise07)) {
5 | exercise07();
6 | }
7 | }
8 |
9 | export default setup07Exercise;
10 |
--------------------------------------------------------------------------------
/src/07-exercise/07-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/07-exercise/07-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 07:
3 | *
4 | * Finish the code of the `exercise07` function so that it:
5 | *
6 | * 1. Stores in the `func` variable an arrow function
7 | * that receives two `a` and `b` parameters
8 | *
9 | * 2. Returns the sum of both parameters
10 | */
11 |
12 | // Finish the code of the function
13 | function exercise07(a, b) {
14 | let func = (a, b) => {
15 | return a + b;
16 | } ;
17 |
18 | // Don’t change the code bellow this line
19 | return func;
20 | }
21 |
22 | // Don’t change the code bellow this line
23 | import setup07Exercise from "./07-exercise-setup";
24 |
25 | if (process.env.NODE_ENV !== "test") {
26 | setup07Exercise(() => {
27 | if (typeof exercise07() === "function") {
28 | console.log(exercise07()(5, 5));
29 | } else {
30 | console.log("Not a function");
31 | }
32 | });
33 | }
34 |
35 | export default exercise07;
36 |
--------------------------------------------------------------------------------
/src/08-exercise/08-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup08Exercise(exercise08) {
4 | if (isFunction(exercise08)) {
5 | exercise08();
6 | }
7 | }
8 |
9 | export default setup08Exercise;
10 |
--------------------------------------------------------------------------------
/src/08-exercise/08-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/08-exercise/08-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 08:
3 | *
4 | * Finish the code of the `exercise08` function so that it:
5 | *
6 | * 1. Converts the `func` function to be an arrow function
7 | *
8 | * 2. The function should perform the same operation,
9 | * return the sum of it’s parameters
10 | */
11 |
12 | // Finish the code of the function
13 | function exercise08() {
14 | let func = (a, b) => {
15 | return a + b;
16 | }
17 |
18 | // Don’t change the code bellow this line
19 | return func;
20 | }
21 |
22 | // Don’t change the code bellow this line
23 | import setup08Exercise from "./08-exercise-setup";
24 |
25 | if (process.env.NODE_ENV !== "test") {
26 | setup08Exercise(() => {
27 | if (typeof exercise08() === "function") {
28 | console.log(exercise08()(5, 5));
29 | } else {
30 | console.log("Not a function");
31 | }
32 | });
33 | }
34 |
35 | export default exercise08;
36 |
--------------------------------------------------------------------------------
/src/09-exercise/09-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup09Exercise(exercise09) {
4 | if (isFunction(exercise09)) {
5 | exercise09();
6 | }
7 | }
8 |
9 | export default setup09Exercise;
10 |
--------------------------------------------------------------------------------
/src/09-exercise/09-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/09-exercise/09-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 09:
3 | *
4 | * Finish the code of the `exercise09` function so that it:
5 | *
6 | * 1. Executes the Array.flat() method on the `days` array
7 | *
8 | * 2. Returns the result
9 | */
10 |
11 | // Finish the code of the function
12 | function exercise09() {
13 | const days = [
14 | ["Monday"],
15 | ["Tuesday"],
16 | ["Wednesday"],
17 | ["Thursday"],
18 | ["Friday"],
19 | ];
20 |
21 | return days.flat();
22 |
23 | }
24 |
25 | // Don’t change the code bellow this line
26 | import setup09Exercise from "./09-exercise-setup";
27 |
28 | if (process.env.NODE_ENV !== "test") {
29 | setup09Exercise(() => console.log(exercise09()));
30 | }
31 |
32 | export default exercise09;
33 |
--------------------------------------------------------------------------------
/src/10-exercise/10-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup10Exercise(exercise10) {
4 | if (isFunction(exercise10)) {
5 | exercise10();
6 | }
7 | }
8 |
9 | export default setup10Exercise;
10 |
--------------------------------------------------------------------------------
/src/10-exercise/10-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/10-exercise/10-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 10:
3 | *
4 | * Finish the code of the `exercise10` function so that it:
5 | *
6 | * 1. Executes the Array.from() method on the `message` variable
7 | *
8 | * 2. Returns the result
9 | */
10 |
11 | // Finish the code of the function
12 | function exercise10() {
13 | const message = "hello-world";
14 |
15 | return Array.from(message);
16 | }
17 |
18 | // Don’t change the code bellow this line
19 | import setup10Exercise from "./10-exercise-setup";
20 |
21 | if (process.env.NODE_ENV !== "test") {
22 | setup10Exercise(() => console.log(exercise10()));
23 | }
24 |
25 | export default exercise10;
26 |
--------------------------------------------------------------------------------
/src/11-exercise/11-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup11Exercise(exercise11) {
4 | if (isFunction(exercise11)) {
5 | exercise11();
6 | }
7 | }
8 |
9 | export default setup11Exercise;
10 |
--------------------------------------------------------------------------------
/src/11-exercise/11-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/11-exercise/11-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 11:
3 | *
4 | * Finish the code of the `exercise11` function so that it:
5 | *
6 | * 1. Receives 2 parameters: `array` and `entry`
7 | *
8 | * @example
9 | *
10 | * function fn (array, entry) {...}
11 | *
12 | * 2. Executes the array.find() method to find the `entry`
13 | * in the `array` parameter that the function receives.
14 | *
15 | * 3. Returns the result
16 | */
17 |
18 | // Finish the code of the function
19 | function exercise11(array, entry) {
20 |
21 | return array.find((element) => element === entry);
22 |
23 | }
24 |
25 |
26 | // Don’t change the code bellow this line
27 | import setup11Exercise from "./11-exercise-setup";
28 |
29 | if (process.env.NODE_ENV !== "test") {
30 | setup11Exercise(() =>
31 | console.log(
32 | exercise11(
33 | ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
34 | "Wednesday"
35 | )
36 | )
37 | );
38 | }
39 |
40 | export default exercise11;
41 |
--------------------------------------------------------------------------------
/src/12-exercise/12-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup12Exercise(exercise12) {
4 | if (isFunction(exercise12)) {
5 | exercise12();
6 | }
7 | }
8 |
9 | export default setup12Exercise;
10 |
--------------------------------------------------------------------------------
/src/12-exercise/12-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/12-exercise/12-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 12:
3 | *
4 | * Finish the code of the `exercise12` function so that it:
5 | *
6 | * 1. Receives 2 parameters: `array` and `entry`
7 | *
8 | * @example
9 | *
10 | * function fn (array, entry) {...}
11 | *
12 | * 2. Executes the array.includes() method to check if the `entry`
13 | * is in the `array` parameter that the function receives.
14 | *
15 | * 3. Returns the result
16 | */
17 |
18 | // Finish the code of the function
19 | function exercise12(array, entry) {
20 |
21 | return array.includes(entry);
22 | }
23 |
24 | // Don’t change the code bellow this line
25 | import setup12Exercise from "./12-exercise-setup";
26 |
27 | if (process.env.NODE_ENV !== "test") {
28 | setup12Exercise(() =>
29 | console.log(
30 | exercise12(
31 | ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
32 | "SOME OTHER DAY"
33 | )
34 | )
35 | );
36 | }
37 |
38 | export default exercise12;
39 |
--------------------------------------------------------------------------------
/src/13-exercise/13-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup13Exercise(exercise13) {
4 | if (isFunction(exercise13)) {
5 | exercise13();
6 | }
7 | }
8 |
9 | export default setup13Exercise;
10 |
--------------------------------------------------------------------------------
/src/13-exercise/13-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/13-exercise/13-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 13:
3 | *
4 | * 1. Create a `const` variable with:
5 | *
6 | * a. the name of: "BASE_URL"
7 | * b. a value of: "https://jsonplaceholder.typicode.com/users"
8 | *
9 | * 2. Export the variable as a named export
10 | *
11 | * @example
12 | *
13 | * export const test = 1;
14 | */
15 |
16 | export const BASE_URL = "https://jsonplaceholder.typicode.com/users";
17 |
--------------------------------------------------------------------------------
/src/14-exercise/14-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup14Exercise(exercise14) {
4 | if (isFunction(exercise14)) {
5 | exercise14();
6 | }
7 | }
8 |
9 | export default setup14Exercise;
10 |
--------------------------------------------------------------------------------
/src/14-exercise/14-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/14-exercise/14-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 14:
3 | *
4 | * 1. Create a `add` function that receives two number
5 | * parameters and returns their sum
6 | *
7 | * 2. Export the function as a named export
8 | *
9 | * @example
10 | *
11 | * export function test() {
12 | * return "something";
13 | * };
14 | */
15 |
16 | export function add(a, b) {
17 | return a + b;
18 | }
19 |
20 | add(2, 3);
21 |
--------------------------------------------------------------------------------
/src/15-exercise/15-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup15Exercise(exercise15) {
4 | if (isFunction(exercise15)) {
5 | exercise15();
6 | }
7 | }
8 |
9 | export default setup15Exercise;
10 |
--------------------------------------------------------------------------------
/src/15-exercise/15-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/15-exercise/15-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 15:
3 | *
4 | * 1. Create a `divide` function that receives two number
5 | * parameters and returns the division of both of them
6 | *
7 | * 2. Export the function as a default export
8 | *
9 | * @example
10 | *
11 | * function test() {
12 | * return "something";
13 | * };
14 | *
15 | * export default test;
16 | */
17 |
18 | export default function divide(a, b) {
19 | return a / b;
20 | }
21 | divide(2, 10);
22 |
--------------------------------------------------------------------------------
/src/16-exercise/16-exercise-fns.js:
--------------------------------------------------------------------------------
1 | export function addOne(num) {
2 | return 1 + num;
3 | }
4 |
5 | export function addTwo(num) {
6 | return 2 + num;
7 | }
8 |
9 | export function addThree(num) {
10 | return 3 + num;
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/src/16-exercise/16-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup16Exercise(exercise16) {
4 | if (isFunction(exercise16)) {
5 | exercise16();
6 | }
7 | }
8 |
9 | export default setup16Exercise;
10 |
--------------------------------------------------------------------------------
/src/16-exercise/16-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/16-exercise/16-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 16:
3 | *
4 | * 1. Export all the functions from the `16-exercise-fns`
5 | * file under the `utils` namespace.
6 | *
7 | * You can use the `export * as name from "./url-path"` command
8 | * to export all the modules in a file under a particular namespace
9 | */
10 |
11 | export * as utils from "./16-exercise-fns";
--------------------------------------------------------------------------------
/src/17-exercise/17-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup17Exercise(exercise17) {
4 | if (isFunction(exercise17)) {
5 | exercise17();
6 | }
7 | }
8 |
9 | export default setup17Exercise;
10 |
--------------------------------------------------------------------------------
/src/17-exercise/17-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/17-exercise/17-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 17:
3 | *
4 | * Complete the code of the exercise17 function so that:
5 | *
6 | * 1. It returns the call to the fetch() method to make
7 | * a network request to the following url:
8 | *
9 | * https://jsonplaceholder.typicode.com/users/1
10 | *
11 | * 2. Obtains the data from the fetch() call and executes several .then()
12 | * method calls until it can get the data returned from the api.
13 | *
14 | * Once it has the data inside the .then() call, it should execute
15 | * the `displayContents` function by passing it as an argument
16 | * the response data returned by the fetch json() method.
17 | *
18 | * function exercise17() {
19 | * return fetch("...")...
20 | * }
21 | */
22 |
23 | // Finish the code of the function
24 | function exercise17() {
25 |
26 | return fetch("https://jsonplaceholder.typicode.com/users/1")
27 | .then((response) => response.json())
28 | .then((data) => displayContents(data))
29 |
30 |
31 | }
32 |
33 | // Don’t change the code bellow this line
34 | function displayContents(data) {
35 | const wrapper = document.querySelector(".ex-wrapper");
36 |
37 | wrapper.textContent = JSON.stringify(data, null, 2);
38 | }
39 |
40 | import setup17Exercise from "./17-exercise-setup";
41 |
42 | if (process.env.NODE_ENV !== "test") {
43 | setup17Exercise(() => exercise17());
44 | }
45 |
46 | export default exercise17;
47 |
--------------------------------------------------------------------------------
/src/18-exercise/18-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup18Exercise(exercise18) {
4 | if (isFunction(exercise18)) {
5 | exercise18();
6 | }
7 | }
8 |
9 | export default setup18Exercise;
10 |
--------------------------------------------------------------------------------
/src/18-exercise/18-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/18-exercise/18-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 18:
3 | *
4 | * Complete the code of the exercise18 function so that it:
5 | *
6 | * 1. Converts the exercise18 function to be of type `async`
7 | *
8 | * 2. Uses the await keyword in front of a fetch() call
9 | * to the following url:
10 | *
11 | * https://jsonplaceholder.typicode.com/users/1
12 | *
13 | * 3. Uses the await keyword again in front of the json() call
14 | * to wait for the data of the promise
15 | *
16 | * 4. Obtains the data from the fetch json() call and executes
17 | * the `displayContents` function by passing it as an argument
18 | * the response data returned by the fetch json() method.
19 | */
20 |
21 | // Finish the code of the function
22 | async function exercise18() {
23 | const response = await fetch("https://jsonplaceholder.typicode.com/users/1");
24 | const data = await response.json();
25 |
26 | displayContents(data);
27 |
28 | }
29 |
30 | // Don’t change the code bellow this line
31 | function displayContents(data) {
32 | const wrapper = document.querySelector(".ex-wrapper");
33 |
34 | wrapper.textContent = JSON.stringify(data, null, 2);
35 | }
36 |
37 | import { removeUnnecessaryItems } from "@babel/preset-env/lib/filter-items";
38 | import setup18Exercise from "./18-exercise-setup";
39 |
40 | if (process.env.NODE_ENV !== "test") {
41 | setup18Exercise(() => exercise18());
42 | }
43 |
44 | export default exercise18;
45 |
--------------------------------------------------------------------------------
/src/19-exercise/19-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup19Exercise(exercise19) {
4 | if (isFunction(exercise19)) {
5 | exercise19();
6 | }
7 | }
8 |
9 | export default setup19Exercise;
10 |
--------------------------------------------------------------------------------
/src/19-exercise/19-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/19-exercise/19-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 19:
3 | *
4 | * 1. Create a class named `Person` that takes in as parameters
5 | *
6 | * firstName
7 | * lastName
8 | *
9 | * 2. The class should use the constructor method to receive
10 | * the parameters for when a new instance of the class
11 | * is created.
12 | *
13 | * 3. Once you have created the Person class, you should
14 | * create a new person using the `new Person(...)`
15 | * expression. Then, you should store the newly created
16 | * person in the `ana` variable.
17 | */
18 |
19 | // Create the Person class
20 | class Person {
21 | constructor(firstName, lastName) {
22 | this.firstName = firstName;
23 | this.lastName = lastName;
24 | }
25 | }
26 |
27 |
28 |
29 | // Create a new instance of the class with the arguments:
30 | //
31 | // firstName: "Ana"
32 | // lastName: "Spark"
33 | //
34 | // Store the new instance in the `ana` variable
35 | let ana = new Person ("Ana", "Spark");
36 |
37 | // Don’t change the code bellow this line
38 | export { Person, ana };
39 |
40 | import setup19Exercise from "./19-exercise-setup";
41 |
42 | if (process.env.NODE_ENV !== "test") {
43 | setup19Exercise(() => console.log(ana));
44 | }
45 |
--------------------------------------------------------------------------------
/src/20-exercise/20-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup20Exercise(exercise20) {
4 | if (isFunction(exercise20)) {
5 | exercise20();
6 | }
7 | }
8 |
9 | export default setup20Exercise;
10 |
--------------------------------------------------------------------------------
/src/20-exercise/20-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/20-exercise/20-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 20:
3 | *
4 | * 1. Create a class named `Person` that takes in as parameters
5 | *
6 | * firstName
7 | * lastName
8 | *
9 | * 2. The class should use the constructor method to receive
10 | * the parameters for when a new instance of the class
11 | * is created.
12 | *
13 | * 3. Once you have created the Person class, you should
14 | * create a new person using the `new Person(...)`
15 | * expression. Then, you should store the newly created
16 | * person in the `ana` variable.
17 | *
18 | * 4. The class should also have a method named `sayName`
19 | * that returns the concatenation of the firstName and lastName
20 | * with an empty space in between.
21 | *
22 | * @example
23 | *
24 | * "Alex Marks"
25 | */
26 |
27 | // Create the Person class
28 | class Person {
29 |
30 | constructor(firstName, lastName) {
31 | this.firstName = firstName;
32 | this.lastName = lastName;
33 | }
34 |
35 | sayName() {
36 | return this.firstName + " " + this.lastName;
37 | }
38 |
39 | }
40 |
41 | // Create a new instance of the class with the arguments:
42 | //
43 | // firstName: "Ana"
44 | // lastName: "Spark"
45 | //
46 | // Store the new instance in the `ana` variable
47 | let ana = new Person ("Ana", "Spark");
48 |
49 | // Don’t change the code bellow this line
50 | export { Person, ana };
51 |
52 | import setup20Exercise from "./20-exercise-setup";
53 |
54 | if (process.env.NODE_ENV !== "test") {
55 | setup20Exercise(() => console.log(ana));
56 | setup20Exercise(() => console.log(ana.sayName()));
57 | }
58 |
--------------------------------------------------------------------------------
/src/21-exercise/21-exercise-setup.js:
--------------------------------------------------------------------------------
1 | import { isFunction } from "../utils/utils";
2 |
3 | function setup21Exercise(exercise21) {
4 | if (isFunction(exercise21)) {
5 | exercise21();
6 | }
7 | }
8 |
9 | export default setup21Exercise;
10 |
--------------------------------------------------------------------------------
/src/21-exercise/21-exercise.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Assembler School ES6
6 |
7 |
11 |
12 |
13 |
14 |
21 |
22 |
23 | Instructions
24 |
25 | Follow the instructions of the exercise and implement your
26 | solution.
27 |
28 |
29 | Then, you can see the result of your solution in the console
30 | and if the solution is correct the test should pass.
31 |
32 |
33 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/21-exercise/21-exercise.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Exercise 21:
3 | *
4 | * 1. Create a class named `Person` that takes in as parameters
5 | *
6 | * firstName
7 | * lastName
8 | *
9 | * 2. The class should use the constructor method to receive
10 | * the parameters for when a new instance of the class
11 | * is created.
12 | *
13 | * 3. Once you have created the Person class, you should
14 | * create a new person using the `new Person(...)`
15 | * expression. Then, you should store the newly created
16 | * person in the `ana` variable.
17 | *
18 | * 4. The class should also have a method named `sayName`
19 | * that returns the concatenation of the firstName and lastName
20 | * with an empty space in between.
21 | *
22 | * @example
23 | *
24 | * "Alex Marks"
25 | *
26 | * 5. Create a class named `Employee` that takes in as parameters
27 | *
28 | * firstName
29 | * lastName
30 | * jobTitle
31 | *
32 | * 6. The `Employee` class should extend the `Person` class and use the
33 | * `super()` method call to pass the `firstName` and `lastName`
34 | * to the `Person` parent class.
35 | *
36 | * 7. The `Employee` class should declare inside the constructor
37 | * the `jobTitle` property as it’s own besides the ones passed
38 | * to the super() call.
39 | *
40 | * 8. The `Employee` class should also declare a method named `getJobTitle`
41 | * that returns the `jobTitle` of the `Employee`
42 | */
43 |
44 | // Create the Person class
45 | class Person {
46 |
47 | constructor (firstName, lastName) {
48 | this.firstName = firstName;
49 | this.lastName = lastName;
50 | }
51 |
52 | sayName() {
53 | return this.firstName + " " + this.lastName;
54 | }
55 |
56 | }
57 |
58 | // Create the Employee class that extends the Person class
59 | class Employee extends Person {
60 |
61 | constructor (firstName, lastName, jobTitle) {
62 |
63 | super(firstName, lastName);
64 |
65 | this.jobTitle = jobTitle;
66 | }
67 |
68 | getJobTitle() {
69 | return this.jobTitle;
70 | };
71 |
72 | }
73 |
74 | // Create a new instance of the `Employee` class with the arguments:
75 | //
76 | // firstName: "Ana"
77 | // lastName: "Spark"
78 | // jobTitle: "Developer"
79 | //
80 | // Store the new instance in the `ana` variable
81 | const ana = new Employee ("Ana", "Spark", "Developer");
82 |
83 | // Don’t change the code bellow this line
84 | export { Person, Employee, ana };
85 |
86 | import setup21Exercise from "./21-exercise-setup";
87 |
88 | if (process.env.NODE_ENV !== "test") {
89 | setup21Exercise(() => console.log(ana));
90 | setup21Exercise(() => console.log(ana.sayName()));
91 | setup21Exercise(() => console.log(ana.getJobTitle()));
92 | }
93 |
--------------------------------------------------------------------------------
/src/__tests__/01-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise01 from "../01-exercise/01-exercise";
2 |
3 | describe("01-exercise", function () {
4 | test("add a default value to each parameter", () => {
5 | expect(exercise01()).toBe(1);
6 | expect(exercise01(5)).toBe(5);
7 | expect(exercise01(5, 5)).toBe(25);
8 | });
9 | });
10 |
--------------------------------------------------------------------------------
/src/__tests__/02-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise02 from "../02-exercise/02-exercise";
2 |
3 | describe("02-exercise", function () {
4 | test("add default values to each key of the destructured parameter object", () => {
5 | expect(exercise02({})).toBe(
6 | "Hello I am Default firstName Default lastName"
7 | );
8 | });
9 |
10 | test("return the concatenation of the values in the object", () => {
11 | expect(
12 | exercise02({
13 | firstName: "John",
14 | lastName: "Second",
15 | })
16 | ).toBe("Hello I am John Second");
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/src/__tests__/03-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise03 from "../03-exercise/03-exercise";
2 |
3 | describe("03-exercise", function () {
4 | test("return the ...rest parameters", () => {
5 | expect(
6 | exercise03("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
7 | ).toEqual(expect.arrayContaining(["Wednesday", "Thursday", "Friday"]));
8 | });
9 | });
10 |
--------------------------------------------------------------------------------
/src/__tests__/04-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise04 from "../04-exercise/04-exercise";
2 |
3 | describe("04-exercise", function () {
4 | test("destructure the array items and return the second element", () => {
5 | expect(
6 | exercise04(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"])
7 | ).toBe("Tuesday");
8 | });
9 | });
10 |
--------------------------------------------------------------------------------
/src/__tests__/05-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise05 from "../05-exercise/05-exercise";
2 |
3 | describe("05-exercise", function () {
4 | test("destructure the array items and set a default value to the second element", () => {
5 | expect(
6 | exercise05(["Monday", undefined, "Wednesday", "Thursday", "Friday"])
7 | ).toBe("DEFAULT");
8 | });
9 |
10 | test("destructure the array items and return the second element", () => {
11 | expect(
12 | exercise05(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"])
13 | ).toBe("Tuesday");
14 | });
15 | });
16 |
--------------------------------------------------------------------------------
/src/__tests__/06-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise06 from "../06-exercise/06-exercise";
2 |
3 | describe("06-exercise", function () {
4 | test("destructure the remaining keys and return the object", () => {
5 | expect(exercise06()).toEqual({
6 | age: 33,
7 | jobTitle: "Student",
8 | company: "Assembler School",
9 | averageGrade: 6.6,
10 | });
11 | });
12 | });
13 |
--------------------------------------------------------------------------------
/src/__tests__/07-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise07 from "../07-exercise/07-exercise";
2 | import { isArrowFunction } from "../utils/utils";
3 |
4 | describe("07-exercise", function () {
5 | test("store an arrow function in the `func` variable", () => {
6 | const result = exercise07();
7 |
8 | expect(typeof result).toBe("function");
9 | });
10 |
11 | test("func should be an arrow function", () => {
12 | expect(function () {
13 | isArrowFunction(exercise07());
14 | }).toThrow(/fn is not a constructor/);
15 | });
16 |
17 | test("func should return the sum of the parameters", () => {
18 | expect(() => {
19 | exercise07()(5, 5);
20 | }).not.toThrow();
21 |
22 | let result = exercise07()(5, 5);
23 |
24 | expect(result).toBe(10);
25 | });
26 | });
27 |
--------------------------------------------------------------------------------
/src/__tests__/08-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise08 from "../08-exercise/08-exercise";
2 | import { isArrowFunction } from "../utils/utils";
3 |
4 | describe("08-exercise", function () {
5 | test("return the `func` function", () => {
6 | const thunk = exercise08();
7 |
8 | expect(typeof thunk).toBe("function");
9 | });
10 |
11 | test("func should be an arrow function", () => {
12 | expect(function () {
13 | isArrowFunction(exercise08());
14 | }).toThrow(/fn is not a constructor/);
15 | });
16 |
17 | test("func should return the sum of the parameters", () => {
18 | expect(() => {
19 | exercise08()(5, 5);
20 | }).not.toThrow();
21 |
22 | let thunk = exercise08()(5, 5);
23 |
24 | expect(thunk).toBe(10);
25 | });
26 | });
27 |
--------------------------------------------------------------------------------
/src/__tests__/09-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise09 from "../09-exercise/09-exercise";
2 |
3 | describe("09-exercise", function () {
4 | let arraySpy = null;
5 |
6 | beforeAll(() => {
7 | arraySpy = jest.spyOn(Array.prototype, "flat");
8 | });
9 |
10 | afterEach(() => {
11 | arraySpy.mockRestore();
12 | });
13 |
14 | test("use the array.flat() method to flatten the array", () => {
15 | exercise09();
16 |
17 | expect(arraySpy).toHaveBeenCalledTimes(1);
18 | });
19 |
20 | test("return the flattened array", () => {
21 | expect(exercise09()).toEqual(
22 | expect.arrayContaining([
23 | "Monday",
24 | "Tuesday",
25 | "Wednesday",
26 | "Thursday",
27 | "Friday",
28 | ])
29 | );
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/src/__tests__/10-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise10 from "../10-exercise/10-exercise";
2 |
3 | describe("10-exercise", function () {
4 | let arraySpy = null;
5 |
6 | beforeAll(() => {
7 | arraySpy = jest.spyOn(Array, "from");
8 | });
9 |
10 | afterEach(() => {
11 | arraySpy.mockRestore();
12 | });
13 |
14 | test("use the Array.from() method to create an array from the string", () => {
15 | exercise10();
16 |
17 | expect(arraySpy).toHaveBeenCalledTimes(1);
18 | expect(arraySpy).toHaveBeenCalledWith("hello-world");
19 | });
20 |
21 | test("return the array of characters", () => {
22 | expect(exercise10()).toEqual([
23 | "h",
24 | "e",
25 | "l",
26 | "l",
27 | "o",
28 | "-",
29 | "w",
30 | "o",
31 | "r",
32 | "l",
33 | "d",
34 | ]);
35 | });
36 | });
37 |
--------------------------------------------------------------------------------
/src/__tests__/11-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise11 from "../11-exercise/11-exercise";
2 |
3 | describe("11-exercise", function () {
4 | let arraySpy = null;
5 |
6 | const days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
7 | const dayToFind = days[2];
8 |
9 | const nums = [1, 20, 3, 5, 4];
10 | const numToFind = nums[3];
11 |
12 | const ages = [22, 26, 55, 25, 5];
13 | const ageToFind = ages[3];
14 |
15 | beforeAll(() => {
16 | arraySpy = jest.spyOn(Array.prototype, "find");
17 | });
18 |
19 | afterEach(() => {
20 | arraySpy.mockRestore();
21 | });
22 |
23 | test("use the array.find() method to find in the array the value of the parameter", () => {
24 | exercise11(days, dayToFind);
25 |
26 | expect(arraySpy).toHaveBeenCalledTimes(1);
27 | });
28 |
29 | test("return the found entry in the array", () => {
30 | const expected1 = exercise11(days, dayToFind);
31 | expect(expected1).toBe(dayToFind);
32 |
33 | const expected2 = exercise11(nums, numToFind);
34 | expect(expected2).toBe(numToFind);
35 |
36 | const expected3 = exercise11(ages, ageToFind);
37 | expect(expected3).toBe(ageToFind);
38 | });
39 | });
40 |
--------------------------------------------------------------------------------
/src/__tests__/12-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise12 from "../12-exercise/12-exercise";
2 |
3 | describe("12-exercise", function () {
4 | let arraySpy = null;
5 |
6 | const days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
7 | const dayToFind = days[2];
8 |
9 | const nums = [1, 20, 3, 5, 4];
10 | const numToFind = nums[3];
11 | const numNotInNums = 2000;
12 |
13 | beforeAll(() => {
14 | arraySpy = jest.spyOn(Array.prototype, "includes");
15 | });
16 |
17 | afterEach(() => {
18 | arraySpy.mockRestore();
19 | });
20 |
21 | test("use the array.includes() method to check if the array includes the entry", () => {
22 | exercise12(days, dayToFind);
23 |
24 | expect(arraySpy).toHaveBeenCalledTimes(1);
25 | expect(arraySpy).toHaveBeenCalledWith(dayToFind);
26 | });
27 |
28 | test("return the result of the includes check", () => {
29 | const expected1 = exercise12(days, dayToFind);
30 | expect(expected1).toBe(true);
31 |
32 | const expected2 = exercise12(nums, numToFind);
33 | expect(expected2).toBe(true);
34 |
35 | const expected3 = exercise12(nums, numNotInNums);
36 | expect(expected3).toBe(false);
37 | });
38 | });
39 |
--------------------------------------------------------------------------------
/src/__tests__/13-exercise.test.js:
--------------------------------------------------------------------------------
1 | describe("13-exercise", function () {
2 | test("export a named export with the name and value indicated", async () => {
3 | const module = await import("../13-exercise/13-exercise");
4 |
5 | expect(module.hasOwnProperty("BASE_URL")).toBe(true);
6 |
7 | expect(module.BASE_URL).toBe(
8 | "https://jsonplaceholder.typicode.com/users"
9 | );
10 | });
11 | });
12 |
--------------------------------------------------------------------------------
/src/__tests__/14-exercise.test.js:
--------------------------------------------------------------------------------
1 | describe("14-exercise", function () {
2 | test("export a named function that returns the sum of it’s parameters", async () => {
3 | const module = await import("../14-exercise/14-exercise");
4 |
5 | expect(module.hasOwnProperty("add")).toBe(true);
6 |
7 | expect(module.add(5, 2)).toBe(7);
8 | });
9 | });
10 |
--------------------------------------------------------------------------------
/src/__tests__/15-exercise.test.js:
--------------------------------------------------------------------------------
1 | describe("15-exercise", function () {
2 | test("default export a function that returns the division of it’s parameters", async () => {
3 | const module = await import("../15-exercise/15-exercise");
4 |
5 | expect(typeof module.default).toBe("function");
6 | expect(module.default.name).toBe("divide");
7 | expect(module.default(10, 2)).toBe(5);
8 | });
9 | });
10 |
--------------------------------------------------------------------------------
/src/__tests__/16-exercise.test.js:
--------------------------------------------------------------------------------
1 | describe("16-exercise", function () {
2 | test("export all the modules under the `utils` namespace", async () => {
3 | const modules = await import("../16-exercise/16-exercise");
4 |
5 | expect(modules).toEqual(
6 | expect.objectContaining({
7 | utils: expect.objectContaining({
8 | addOne: expect.any(Function),
9 | addTwo: expect.any(Function),
10 | addThree: expect.any(Function),
11 | }),
12 | })
13 | );
14 | });
15 | });
16 |
--------------------------------------------------------------------------------
/src/__tests__/17-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise17 from "../17-exercise/17-exercise";
2 |
3 | describe("17-exercise", function () {
4 | const FETCH_RESPONSE_DATA = {
5 | id: 1,
6 | name: "Leanne Graham",
7 | phone: "1-770-736-8031 x56442",
8 | username: "Bret",
9 | website: "hildegard.org",
10 | };
11 |
12 | beforeAll(() => {
13 | document.body.innerHTML = ` `;
14 |
15 | global.fetch = jest.fn(() => {
16 | return Promise.resolve({
17 | json() {
18 | return Promise.resolve(FETCH_RESPONSE_DATA);
19 | },
20 | });
21 | });
22 | });
23 |
24 | afterAll(() => {
25 | fetch.mockRestore();
26 | });
27 |
28 | test("use fetch to make a network call", async () => {
29 | await exercise17();
30 |
31 | expect(fetch).toHaveBeenCalledTimes(1);
32 | });
33 |
34 | test("pass the data from the fetch call to the displayContents function", async () => {
35 | await exercise17();
36 |
37 | const wrapper = document.querySelector(".ex-wrapper");
38 |
39 | expect(wrapper.innerHTML).toMatch(/Leanne Graham/);
40 | });
41 | });
42 |
--------------------------------------------------------------------------------
/src/__tests__/18-exercise.test.js:
--------------------------------------------------------------------------------
1 | import exercise18 from "../18-exercise/18-exercise";
2 | import { isAsyncFunction } from "../utils/utils";
3 |
4 | describe("18-exercise", function () {
5 | const FETCH_RESPONSE_DATA = {
6 | id: 1,
7 | name: "Leanne Graham",
8 | phone: "1-770-736-8031 x56442",
9 | username: "Bret",
10 | website: "hildegard.org",
11 | };
12 |
13 | beforeAll(() => {
14 | document.body.innerHTML = ` `;
15 |
16 | global.fetch = jest.fn(() => {
17 | return Promise.resolve({
18 | json() {
19 | return Promise.resolve(FETCH_RESPONSE_DATA);
20 | },
21 | });
22 | });
23 | });
24 |
25 | afterAll(() => {
26 | fetch.mockRestore();
27 | });
28 |
29 | test("convert the exercise18 to be of type async", async () => {
30 | expect(isAsyncFunction(exercise18)).toBe(true);
31 | });
32 |
33 | test("use fetch to make a network call", async () => {
34 | await exercise18();
35 |
36 | expect(fetch).toHaveBeenCalledTimes(1);
37 | });
38 |
39 | test("pass the data from the fetch call to the displayContents function", async () => {
40 | await exercise18();
41 |
42 | const wrapper = document.querySelector(".ex-wrapper");
43 |
44 | expect(wrapper.innerHTML).toMatch(/Leanne Graham/);
45 | });
46 | });
47 |
--------------------------------------------------------------------------------
/src/__tests__/19-exercise.test.js:
--------------------------------------------------------------------------------
1 | import { Person, ana } from "../19-exercise/19-exercise";
2 |
3 | describe("19-exercise", function () {
4 | test("create a class Person", async () => {
5 | const expectedAna = {
6 | firstName: "Ana",
7 | lastName: "Spark",
8 | };
9 |
10 | const newAna = new Person("Ana", "Spark");
11 |
12 | expect(expectedAna).toEqual(ana);
13 | expect(expectedAna).toEqual(newAna);
14 | });
15 | });
16 |
--------------------------------------------------------------------------------
/src/__tests__/20-exercise.test.js:
--------------------------------------------------------------------------------
1 | import { Person, ana } from "../20-exercise/20-exercise";
2 |
3 | describe("20-exercise", function () {
4 | test("create a class Person that has a method sayName", async () => {
5 | const expectedAna = {
6 | firstName: "Ana",
7 | lastName: "Spark",
8 | };
9 |
10 | const newAna = new Person("Ana", "Spark");
11 |
12 | expect(expectedAna).toEqual(ana);
13 | expect(expectedAna).toEqual(newAna);
14 |
15 | expect(ana.sayName()).toEqual(`Ana Spark`);
16 | expect(newAna.sayName()).toEqual(`Ana Spark`);
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/src/__tests__/21-exercise.test.js:
--------------------------------------------------------------------------------
1 | import { Person, Employee, ana } from "../21-exercise/21-exercise";
2 |
3 | describe("21-exercise", function () {
4 | test("create a class Employee that extends the Person class", async () => {
5 | const expectedAna = {
6 | firstName: "Ana",
7 | lastName: "Spark",
8 | jobTitle: "Developer",
9 | };
10 |
11 | const newAna = new Employee("Ana", "Spark", "Developer");
12 |
13 | expect(expectedAna).toEqual(ana);
14 | expect(expectedAna).toEqual(newAna);
15 |
16 | expect(ana.sayName()).toEqual(`Ana Spark`);
17 | expect(ana.getJobTitle()).toEqual(`Developer`);
18 |
19 | expect(newAna.sayName()).toEqual(`Ana Spark`);
20 | expect(newAna.getJobTitle()).toEqual(`Developer`);
21 |
22 | expect(ana).toBeInstanceOf(Employee);
23 | expect(ana).toBeInstanceOf(Person);
24 |
25 | expect(newAna).toBeInstanceOf(Employee);
26 | expect(newAna).toBeInstanceOf(Person);
27 | });
28 | });
29 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | .list {
2 | margin: 0;
3 | padding: 0;
4 | }
5 |
6 | .list--body li {
7 | list-style-type: disc;
8 | margin-left: 16px;
9 | }
10 |
11 | .index-list {
12 | margin: 0;
13 | padding: 0;
14 | display: flex;
15 | flex-wrap: wrap;
16 | }
17 |
18 | .list-item-index {
19 | display: inline-flex;
20 | margin-right: 32px;
21 | margin-top: 16px;
22 | }
23 |
24 | .list-item {
25 | display: inline-block;
26 | margin-right: 12px;
27 | margin-bottom: 12px;
28 | }
29 |
30 | code {
31 | font-size: 16px;
32 | color: darkorchid;
33 | padding: 4px;
34 | background-color: aliceblue;
35 | }
36 |
--------------------------------------------------------------------------------
/src/utils/utils.js:
--------------------------------------------------------------------------------
1 | export function isFunction(fn) {
2 | return typeof fn === "function";
3 | }
4 |
5 | export function isArrowFunction(fn) {
6 | new fn();
7 | }
8 |
9 | export function isAsyncFunction(fn) {
10 | return Object.prototype.toString.call(fn).includes("AsyncFunction");
11 | }
12 |
--------------------------------------------------------------------------------