Skip to content

Commit 732ccbf

Browse files
authored
Merge pull request HackYourFuture#534 from HackYourFuture/wilgert-week2-files
Add files used in videos
2 parents 781152b + 91a5be7 commit 732ccbf

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

assets/array-methods-exercises.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const flowers = [
2+
{ name: 'tulip', color: 'red' },
3+
{ name: 'dandelion', color: 'yellow' },
4+
{ name: 'rose', color: 'red' },
5+
{ name: 'daisy', color: 'white' },
6+
{ name: 'lily', color: 'white' },
7+
];
8+
9+
// Exercise 1
10+
// use `map` to make the first letter of al flowers a capital.
11+
// so 'tulip' becomes 'Tulip' etc.
12+
13+
// Exercise 2
14+
// use `filter` to get only the flowers with a name of 4 characters
15+
16+
// Exercise 3
17+
// use `reduce` to create an object that contains
18+
// the total number of flowers for each color
19+
20+
// Exercise 4 (bonus)
21+
// use `some` or `every` in combination with another array method
22+
// to find out if all flowers with five letters are red

assets/sync-async.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const greenGrocer = {
2+
buyApples: function(quantity) {
3+
return quantity + ' apples';
4+
},
5+
buyTomatoes: function(quantity) {
6+
return quantity + ' tomatoes';
7+
},
8+
buyCauliflower: function(quantity) {
9+
return quantity + ' cauliflower';
10+
},
11+
};
12+
13+
const cheeseShop = {
14+
buyCheese: function(type, weight) {
15+
this.cutCheese(type, weight);
16+
17+
return weight + 'gr ' + type + ' cheese';
18+
},
19+
20+
cutCheese: function(type, weight) {
21+
const stopTime = Date.now() + 100;
22+
while (Date.now() < stopTime);
23+
},
24+
};
25+
26+
const bakery = {
27+
buyBread: function(breadReadyCallback, type, quantity) {
28+
setTimeout(function() {
29+
breadReadyCallback(quantity + ' ' + type);
30+
}, 1000);
31+
},
32+
};
33+
34+
function visitGreengrocer() {
35+
console.log('=== Greengrocer ===');
36+
37+
const beforeBuy = Date.now();
38+
39+
const fruitsAndVegetables = [
40+
greenGrocer.buyApples(2),
41+
greenGrocer.buyTomatoes(2),
42+
greenGrocer.buyCauliflower(1),
43+
];
44+
45+
const timeTaken = (Date.now() - beforeBuy).toFixed(2);
46+
47+
console.log('You bought: ', fruitsAndVegetables);
48+
console.log('This took: ' + timeTaken + 'ms\n');
49+
}
50+
51+
function visitCheeseShop() {
52+
console.log('=== Cheese Shop ===');
53+
const beforeBuy = Date.now();
54+
55+
const cheese = cheeseShop.buyCheese('belegen', 500);
56+
57+
const timeTaken = (Date.now() - beforeBuy).toFixed(2);
58+
59+
console.log('You bought: ' + cheese + '');
60+
console.log('This took: ' + timeTaken + 'ms\n');
61+
}
62+
63+
function visitBakery() {
64+
console.log('=== Bakery ===');
65+
const beforeBuy = Date.now();
66+
67+
const breadReady = function(bread) {
68+
const timeTaken = (Date.now() - beforeBuy).toFixed(2);
69+
console.log('--- Callback from Bakery ---');
70+
console.log('You bought: ' + bread + '');
71+
console.log('This took: ' + timeTaken + 'ms\n');
72+
};
73+
74+
bakery.buyBread(breadReady, 'fijn volkoren', 1);
75+
console.log(`We'll call you back!\n`);
76+
}
77+
78+
visitGreengrocer(); // ?.
79+
visitBakery(); // ?.
80+
visitCheeseShop(); // ?.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy