-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (41 loc) · 1.34 KB
/
app.js
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
const body = document.querySelector('body')
const button = document.querySelector('.button')
const word = document.createElement('h1')
const def = document.createElement('p')
const randomword = () => {
fetch('https://random-word-api.herokuapp.com/word?number=1')
.then(response => {
return response.json();
})
.then(response => {
word.textContent = "/" + response;
document.getElementById("demo").appendChild(word)
randomDefinition(word)
})
.catch(err => {
console.log(err)
})
}
const randomDefinition = (word) => {
// console.log(word.textContent)
fetch('https://dictionaryapi.com/api/v3/references/collegiate/json/'+(word.textContent)+"?key="+"0434c413-f173-4f94-948d-a4ae26f3447f")
.then(response => {
return response.json();
})
.then(response => {
if(response[0].shortdef!=null){
def.textContent = response[0].shortdef[0];
}
else{
def.textContent = "No definition available"
}
document.getElementById("demo").appendChild(def)
console.log(response[0].shortdef[0])
})
.catch(err => {
console.log(err)
})
}
button.addEventListener('click', function () {
randomword();
})