Add lesson 2: Functions and arrow functions

Daniel Tanaka 1 year ago
parent 6c690c658e commit bb024e826b3304e3f35aaf4701d9ad37bc876d4e
3 changed files with 34 additions and 0 deletions
+19-0lessons/02-functions-and-arrow-functions/README.md ADDED
@@ -0,0 +1,19 @@
1+# Lesson 2: Functions and arrow functions
2+
3+In this lesson you'll work through functions and arrow functions step by step, with short exercises after each idea.
4+
5+Full lesson: [https://glibcode.net/courses/javascript-web/lessons/2](https://glibcode.net/courses/javascript-web/lessons/2)
6+
7+## Files
8+
9+- `functions.js`: function declarations and arrow functions
10+
11+## Run it
12+
13+```sh
14+node functions.js
15+```
16+
17+## Exercises
18+
19+See [exercises.md](exercises.md). Ask in the forum once you've tried.
+5-0lessons/02-functions-and-arrow-functions/exercises.md ADDED
@@ -0,0 +1,5 @@
1+# Exercises: lesson 2
2+
3+1. Run `functions.js` and change one value. Write down what you expect, then run it again and compare.
4+2. Make the example ask for its input instead of using a fixed value.
5+3. Explain the example to someone who hasn't taken the course. Which part was hardest to explain?
+10-0lessons/02-functions-and-arrow-functions/functions.js ADDED
@@ -0,0 +1,10 @@
1+function greet(name) {
2+ return `Hello, ${name}!`;
3+}
4+
5+const shout = text => text.toUpperCase() + "!";
6+const add = (a, b = 1) => a + b;
7+
8+console.log(greet("Lin"));
9+console.log(shout("hi"));
10+console.log(add(2), add(2, 3));