Skip to content

Commit 01f0294

Browse files
authored
Added the Dictionary API
1 parent 2cceba1 commit 01f0294

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

Search Word Definitions/api.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"word": "amazing",
3+
"results": [
4+
{
5+
"definition": "inspiring awe or admiration or wonder",
6+
"partOfSpeech": "adjective",
7+
"synonyms": [
8+
"awe-inspiring",
9+
"awesome",
10+
"awful",
11+
"awing"
12+
],
13+
"similarTo": [
14+
"impressive"
15+
],
16+
"examples": [
17+
"New York is an amazing city"
18+
]
19+
},
20+
{
21+
"definition": "surprising greatly",
22+
"partOfSpeech": "adjective",
23+
"synonyms": [
24+
"astonishing"
25+
],
26+
"similarTo": [
27+
"surprising"
28+
],
29+
"examples": [
30+
"she does an amazing amount of work"
31+
]
32+
}
33+
],
34+
"syllables": {
35+
"count": 3,
36+
"list": [
37+
"a",
38+
"maz",
39+
"ing"
40+
]
41+
},
42+
"pronunciation": {
43+
"all": "ə'meɪzɪŋ"
44+
},
45+
"frequency": 4.94
46+
}

Search Word Definitions/app.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
console.log('Hello');
2+
str = "";
3+
4+
const fetchBtn = document.getElementById('fetchBtn');
5+
const deleteBtn = document.getElementById('deleteBtn');
6+
7+
const inputtext = document.getElementById('inputtext');
8+
const show = document.getElementById('list');
9+
10+
fetchBtn.addEventListener('click',getdata);
11+
deleteBtn.addEventListener('click',deletedata);
12+
13+
function getdata(){
14+
15+
const xhr = new XMLHttpRequest();
16+
17+
xhr.open('GET',`https://mashape-community-urban-dictionary.p.rapidapi.com/define?term=${inputtext.value}`,true);
18+
xhr.setRequestHeader("x-rapidapi-key", "3713d5b39dmshf1764344d8244d5p116e9ajsneb81024be405");
19+
xhr.setRequestHeader("x-rapidapi-host", "mashape-community-urban-dictionary.p.rapidapi.com");
20+
21+
xhr.onload = function(){
22+
const response = xhr.responseText;
23+
const obj = JSON.parse(response);
24+
// console.log(obj.list[0]);
25+
str = str + `<strong>${inputtext.value} </strong><li> ${obj.list[0].definition}</li> <br>`;
26+
show.innerHTML = str;
27+
// inputtext.value = "";
28+
}
29+
30+
31+
xhr.send();
32+
}
33+
34+
function deletedata(){
35+
show.innerHTML = "";
36+
str = "";
37+
}

0 commit comments

Comments
 (0)