forked from ZCW-Java8-1/WhatsTypescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randoFunctions.ts
58 lines (43 loc) · 1.84 KB
/
randoFunctions.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
// const data = [ { "definition": "an expression of greeting", "word": "hello" }, { "definition": "a telephone call", "word": "hello" } ];
// const definitions = data.map(entry => entry.definition);
// const words = data.map(entry => entry.word);
// console.log(definitions); // ['an expression of greeting', 'a telephone call'] console.log(words); // ['hello', 'hello']
// -------
// const word: string = "test";
// const definition: string = "a procedure or test to determine the quality, performance, or reliability of something";
// const apiUrl: string = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;
// const response = await fetch(apiUrl);
// const data = await response.json();
// const word: string = data.word;
// const definition: string = data.definition;
// ------
// function fetchJSON(text: string) {
// fetch('https://api.dictionaryapi.dev/api/v2/entries/en/' + text)
// .then(response => response.json())
// .then(data => {
// console.log(data);
// localStorage.setItem('definition', JSON.stringify(data));
// });
// }
// const defsdiv = document.getElementById('definitions');
// form.onsubmit = () => {
// const formData = new FormData(form!);
// console.log(formData);
// const text = formData.get('defineword') as string;
// console.log("on submit", text);
// const element = document.getElementById('worddefined');
// if (element){
// element.textContent = text;
// }
// defsdiv!.innerHTML = '';
// GetWords(text)
// .then(defintions => {
// defintions.forEach(d => {
// defsdiv!.innerHTML += `<p>${d}</p>`;
// });
// })
// .catch(_ => {
// defsdiv!.innerHTML += `<p class="lead">Error: Unable to find any defintions for ${text}.</p>`;
// });
// return false; // prevent reload
// };