-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·66 lines (53 loc) · 2.05 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const resdiv = document.querySelector(".result");
const wordele = document.querySelector(".word");
const phonetics = document.querySelector(".phonetics");
const audio = document.querySelector(".audio");
const wordMeaning = document.querySelector(".word-definition");
const synonyms = document.querySelector(".synonyms");
const wrongword = document.querySelector(".wrongword");
const url = "https://api.dictionaryapi.dev/api/v2/entries/en/"
// funtion to handle all the word
const handle = async (event) =>
{
if (event.keyCode === 13)
{
const word = event.target.value;
//make a req to the api
const result = await fetch (url + word);
const data = await result.json();
resdiv.style.display = "block";
// audio.src = data[0].phonetics[0].audio;
if (result.ok)
{
wordele.innerText = data[0].word;
phonetics.innerText = data[0].phonetics[0].text;
audio.src = data[0].phonetics[0].audio;
wordMeaning.innerText = data[0].meanings[0].definitions[0].definition;
const synonymsarray = data[0].meanings[0].definitions[0].synonyms;
let synonymsdata= "";
if (synonymsarray)
{
for (let i = 0; i < synonymsarray.length; i++)
{
synonymsdata += `<p class ="pills">${synonymsarray[i]}</p>`
}
synonyms.innerHTML = synonymsdata;
return;
}
else
{
synonyms.innerHTML = `<p class="pills">No synonyms available</p>`;
}
}
else
{
audio.style.display = "none";
document.querySelectorAll(".meaningheading")[0].style.display = "none";
document.querySelectorAll(".meaningheading")[1].style.display = "none";
phonetics.innerHTML = "";
wordele.innerText = data.title ;
wordMeaning.innerText = data.message;
synonyms.innerHTML = `<p class="pills">No synonyms available</p>`;
}
}
};