-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexercise_2.ts
More file actions
72 lines (59 loc) · 1.58 KB
/
exercise_2.ts
File metadata and controls
72 lines (59 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* ----------------------------------------------------------------------------------------------------
* Exercise 2/5: Function return types
* Type the return type of the functions without using the any or unknown keywords.
* ----------------------------------------------------------------------------------------------------
*/
function sayHello(name: string) {
console.log(`Hello ${name}`);
}
sayHello('John Hammond');
const person = {
name: 'John',
age: 67,
children: [
'Dirk',
'Dries'
],
address: {
houseNumber: 53,
street: 'Redenstraat',
zipCode: '9024BG'
}
}
function getAge() {
return person.age;
}
function getName() {
return person.name;
}
function getChildren() {
return person.children;
}
function getAddress() {
return person.address;
}
function getAgeAsync() {
return Promise.resolve(getAge());
}
console.log(getName());
console.log(getChildren());
console.log(getAddress());
(async () => {
const age = await getAgeAsync();
console.log(age);
})();
/*
* Write a function that (optionally) takes a name and returns either:
* "There's a cookie left for {name}, but please leave some for me." - If there is a name
* "There's a cookie left for you, but please leave some for me." - If there's no name
*/
// Bonusss for those that are blazing fast
async function getDitto() {
const response = await fetch('https://pokeapi.co/api/v2/pokemon/ditto', { method: 'GET' });
return response.json();
}
(async () => {
const ditto = await getDitto();
console.log(ditto);
})();