-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
68 lines (49 loc) · 1.39 KB
/
main.ts
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
async function main(): Promise<void> {
while (true) {
const categories = await getCategories();
const category = chooseCategory(categories);
const joke = await getJoke(category);
printJoke(joke);
await rateJoke(joke);
if (!askForAnotherJoke()) {
break;
}
}
}
const BASE_API_URL = 'https://api.jokes.one';
// const BASE_API_URL = 'https://api.chucknorris.io/jokes';
type DataCategories = {
contents: {
categories: {
[key: string]: {
category: string;
title: string;
description: string;
background: string;
}
};
};
};
async function getCategories(): Promise<string[]> {
const response = await fetch(`${BASE_API_URL}/jod/categories`);
console.log(response);
const data: DataCategories = await response.json();
console.log(data);
return Object.keys(data.contents.categories);
}
function chooseCategory(categories: string[]): string {
return categories[0];
}
async function getJoke(category: string): Promise<string> {
return '';
}
function printJoke(joke: string): void {
console.log(joke);
}
async function rateJoke(joke: string): Promise<void> {
return;
}
function askForAnotherJoke(): boolean {
return true;
}
main().then(() => console.log('bye bye')).catch(console.error);