Skip to content

Commit f8758c8

Browse files
Adding workshop recordings on functions, testing, arrays and objects (#1258)
1 parent f648adb commit f8758c8

File tree

8 files changed

+293
-0
lines changed

8 files changed

+293
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
+++
2+
title = '📼 Solving Problems with Functions'
3+
4+
time = 60
5+
facilitation = false
6+
emoji= '🗄️'
7+
[objectives]
8+
1='Practice solving problems with functions'
9+
[build]
10+
render = 'never'
11+
list = 'local'
12+
publishResources = false
13+
14+
+++
15+
16+
{{<youtube>}}https://youtu.be/foc8E5Yi4c0{{</youtube>}}
17+
18+
To get the most out of this workshop - don't just watch, code along 💻
19+
You can use the code samples below as a starting point.
20+
21+
### Exercise 1
22+
23+
```js
24+
// Write a function that will calculate the area of a rectangle
25+
// given it's width and height
26+
27+
let width = 3
28+
let height = 4
29+
30+
function calculateArea() {
31+
const area = width * height
32+
}
33+
34+
console.log(area)
35+
```
36+
37+
### Exercise 2
38+
39+
```js
40+
function capitaliseFirstLetter(name) {
41+
console.log(name[0].toUpperCase() + name.substring(1))
42+
}
43+
44+
function createGreeting(name) {
45+
const result = capitaliseFirstLetter(name)
46+
return `Welcome ${result}`
47+
}
48+
49+
const greeting = createGreeting('barath')
50+
console.log(greeting)
51+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
+++
2+
title = '📼 Testing Workshop'
3+
4+
time = 60
5+
facilitation = false
6+
emoji= '🗄️'
7+
[objectives]
8+
1='Practice solving problems while testing'
9+
[build]
10+
render = 'never'
11+
list = 'local'
12+
publishResources = false
13+
14+
+++
15+
16+
{{<youtube>}}https://youtu.be/SMy1jWCg8kI{{</youtube>}}
17+
18+
To get the most out of this workshop - don't just watch, code along 💻
19+
You can use the code samples below as a starting point.
20+
21+
### Exercise 1
22+
23+
```js
24+
// Create a function that takes three numbers as parameters
25+
// and returns the largest of the three
26+
```
27+
28+
### Exercise 2
29+
30+
- Start with an empty folder
31+
- Create a new NodeJS project: `npm init -y`
32+
- Install Jest as a dependency: `npm i jest --save-dev`
33+
- In package.json, change `"test": "echo \"Error: no test specified\" && exit 1"` to `"test": "jest"`
34+
- Create a file for our first exercise: `example1.test.js`
35+
- You can run your tests using `npm test`
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
+++
2+
title = '📼 Arrays Workshop'
3+
4+
time = 60
5+
facilitation = false
6+
emoji= '🗄️'
7+
[objectives]
8+
1='Practice solving problems with arrays'
9+
[build]
10+
render = 'never'
11+
list = 'local'
12+
publishResources = false
13+
14+
+++
15+
16+
{{<youtube>}}https://youtu.be/a_4gTaNYwTU{{</youtube>}}
17+
18+
To get the most out of this workshop - don't just watch, code along 💻
19+
You can use the code samples below as a starting point.
20+
21+
### Exercise 1
22+
23+
```js
24+
// Can you fix this code?
25+
function doubleAllNumbers() {
26+
let doubledNumbers
27+
28+
for(let n of numbers) {
29+
doubledNumbers.push(n * 2)
30+
}
31+
32+
return doubledNumbers
33+
}
34+
35+
const myNums = [10, 20, 30]
36+
doubleAllNumbers(myNums)
37+
console.log(myNums)
38+
```
39+
40+
### Exercise 2
41+
42+
```js
43+
// Write a function which takes an array as a parameter
44+
// and swaps the first element with the last element
45+
46+
function swapFirstAndLast(arr) {
47+
}
48+
49+
const myArray = [5, 2, 3, 4, 1]
50+
swapFirstAndLast(myArray)
51+
console.log(myArray) // what output should we expect?
52+
```
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
+++
2+
title = '📼 Objects Workshop'
3+
4+
time = 60
5+
facilitation = false
6+
emoji= '🗄️'
7+
[objectives]
8+
1='Practice solving problems with objects'
9+
[build]
10+
render = 'never'
11+
list = 'local'
12+
publishResources = false
13+
14+
+++
15+
16+
{{<youtube>}}https://youtu.be/CHu7iEmuZV4{{</youtube>}}
17+
18+
To get the most out of this workshop - don't just watch, code along 💻
19+
You can use the code samples below as a starting point.
20+
21+
### Exercise 1
22+
23+
```js
24+
// Write a function that returns true if I can eat the ice cream
25+
// The function has 1 parameter representing an ice cream object
26+
// I can eat the ice cream if it is lactose-free and contains less than 10 grams of sugar
27+
28+
function canEat(iceCream) {}
29+
30+
const iceCream1 = {
31+
flavour: "Vanilla",
32+
lactoseFree: false,
33+
gramsOfSugarPerScoop: 12,
34+
}
35+
36+
const iceCream2 = {
37+
flavour: "Mango Sorbet",
38+
lactoseFree: true,
39+
gramsOfSugarPerScoop: 10,
40+
}
41+
42+
const iceCream3 = {
43+
flavour: "Coconut",
44+
lactoseFree: true,
45+
gramsOfSugarPerScoop: 8,
46+
}
47+
48+
const iceCream4 = {
49+
flavour: "Strawberry",
50+
lactoseFree: false,
51+
gramsOfSugarPerScoop: 8,
52+
}
53+
54+
const iceCream5 = {
55+
flavour: "Lemon Sorbet",
56+
lactoseFree: true,
57+
gramsOfSugarPerScoop: 7,
58+
}
59+
60+
console.log(canEat(iceCream1)) // what should this output?
61+
console.log(canEat(iceCream2)) // what should this output?
62+
console.log(canEat(iceCream3)) // what should this output?
63+
console.log(canEat(iceCream4)) // what should this output?
64+
console.log(canEat(iceCream5)) // what should this output?
65+
```
66+
67+
### Exercise 2
68+
69+
```js
70+
// Write a function called `getCheapest` that will take 2 book objects as parameters
71+
// and return the name of the cheaper book
72+
73+
const fictionBook = {
74+
title: "1984",
75+
author: "George Orwell",
76+
category: "Dystopian Fiction",
77+
subcategory: "Political",
78+
cost: 9.99,
79+
}
80+
81+
const productivityBook = {
82+
title: "Atomic Habits",
83+
author: "James Clear",
84+
category: "Self-Help",
85+
subcategory: "Productivity",
86+
cost: 16.2,
87+
}
88+
89+
// this should output 1984
90+
console.log(getCheapest(fictionBook, productivityBook))
91+
```
92+
93+
### Exercise 3
94+
95+
```js
96+
// Write a function that takes an array of ice cream objects as a parameter
97+
// and returns an array of the names of ice creams I can eat
98+
// I can eat the ice cream if it is lactose-free and contains less than 10 grams of sugar
99+
// Use the solution from Exercise 1 to help you
100+
function whichIceCreamsCanIEat(iceCreams) {
101+
}
102+
103+
const iceCream1 = {
104+
flavour: "Vanilla",
105+
lactoseFree: false,
106+
gramsOfSugarPerScoop: 12,
107+
}
108+
109+
const iceCream2 = {
110+
flavour: "Mango Sorbet",
111+
lactoseFree: true,
112+
gramsOfSugarPerScoop: 10,
113+
}
114+
115+
const iceCream3 = {
116+
flavour: "Coconut",
117+
lactoseFree: true,
118+
gramsOfSugarPerScoop: 8,
119+
}
120+
121+
const iceCream4 = {
122+
flavour: "Strawberry",
123+
lactoseFree: false,
124+
gramsOfSugarPerScoop: 8,
125+
}
126+
127+
const iceCream5 = {
128+
flavour: "Lemon Sorbet",
129+
lactoseFree: true,
130+
gramsOfSugarPerScoop: 7,
131+
}
132+
133+
const allIceCreams = [
134+
iceCream1,
135+
iceCream2,
136+
iceCream3,
137+
iceCream4,
138+
iceCream5,
139+
]
140+
141+
const iceCreamsICanEat = whichIceCreamsCanIEat(allIceCreams)
142+
console.log(iceCreamsICanEat) // what should this output?
143+
```

org-cyf-itp/content/data-groups/sprints/1/prep/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ src="module/js2/side-effects"
3838
name="Implementing all the cases"
3939
src="module/js2/more-median-cases"
4040
[[blocks]]
41+
name="Solving problems with arrays 📼"
42+
src="module/js2/arrays-workshop"
43+
[[blocks]]
4144
name="Failing Fast"
4245
src="https://cyf-pd.netlify.app/blocks/fail-fast-prep/readme/"
4346
+++

org-cyf-itp/content/data-groups/sprints/2/prep/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ name="[ ] access with variables"
3232
src="module/js2/multiple-params"
3333
name="Parsing multiple params"
3434
[[blocks]]
35+
name="Solving problems with objects 📼"
36+
src="module/js2/objects-workshop"
37+
[[blocks]]
3538
src="https://cyf-pd.netlify.app/blocks/prep-conflict-resolution/readme/"
3639
name="Conflict Resolution"
3740
+++

org-cyf-itp/content/structuring-data/sprints/1/prep/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ src="module/js1/reuse"
4444
[[blocks]]
4545
name="Parameters"
4646
src="module/js1/parameters"
47+
[[blocks]]
48+
name="Solving problems with functions 📼"
49+
src="module/js1/functions-workshop"
4750
+++

org-cyf-itp/content/structuring-data/sprints/3/prep/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ name="Anonymous functions"
3737
[[blocks]]
3838
src="module/js1/arrow-functions"
3939
name="Arrow functions"
40+
[[blocks]]
41+
name="Solving problems while testing 📼"
42+
src="module/js1/testing-workshop"
4043
+++

0 commit comments

Comments
 (0)