-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIcall.html
More file actions
60 lines (48 loc) · 1.87 KB
/
APIcall.html
File metadata and controls
60 lines (48 loc) · 1.87 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="author" content="Adolfo Barrientos">
<title>API Call</title>
</head>
<body>
<button id="data" onclick="def()">Click Me For Dictionary Entry!</button>
<script>
function def(){
let num = 3
let entry = document.createElement('p')
let word = document.createElement('p')
let sDef = document.createElement('p')
let stems = document.createElement('p')
let speech = document.createElement('p')
document.body.appendChild(entry)
document.body.appendChild(word)
document.body.appendChild(speech)
document.body.appendChild(sDef)
document.body.appendChild(stems)
let url = "https://www.dictionaryapi.com/api/v3/references/collegiate/json/test?key=192b4593-3bb6-46e2-9417-a37b03271b5e"
console.log("API Call Successful!")
fetch(url)
.then (Response =>{
return Response.json()
})
.then(json =>{
entry.innerHTML = "Entry: " + json[num].hom
console.log("id added!")
word.innerHTML = "Word: " + json[num].meta.src
console.log("word added!")
speech.innerHTML = "Parts of Speech: " + json[num].fl
console.log("Parts of Speech added!")
sDef.innerHTML = "Definition: " + json[num].shortdef
console.log("definition added!")
stems.innerHTML = "Stems: " + json[num].meta.stems
console.log("stems added!")
})
.catch(err =>{
console.log('Errors: ' + err.message)
})
}
</script>
</body>
</html>