-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
41 lines (32 loc) · 1.63 KB
/
script.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
let searchInput = document.querySelector('#searchInput');
let searchBtn = document.querySelector('#searchBtn');
const getData = async function(searchValue){
document.querySelector('.text').innerHTML = "";
let data = await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${searchValue}`);
let response = await data.json();
if(response.title == "No Definitions Found" ){
let div = document.createElement('div');
div.classList.add('detail');
div.innerHTML = `<h2>No word Found</h2>`;
document.querySelector('.text').appendChild(div);
}
console.log(response);
let div = document.createElement('div');
div.classList.add('detail');
div.innerHTML = `
<h2>Word : <span>${response[0].word}</span></h2>
<p>Meaning : <span>${response[0].meanings[0].definitions[0].definition}</span></p>
<p>Examples : <span>${response[0].meanings[0].definitions[0].example == undefined ? "Not Found" : response[0].meanings[0].definitions[0].example}</span></p>
<p>Synonyms : <span>${response[0].meanings[0].synonyms == "" ? "Not Found" : response[0].meanings[0].synonyms}</span></p>
<p>Antonyms : <span>${response[0].meanings[0].antonyms == "" ? "Not Found" : response[0].meanings[0].antonyms}</span></p>
<a href=${response[0].sourceUrls[0]} target = "_blank">Read More</a> `;
document.querySelector('.text').appendChild(div);
}
searchBtn.addEventListener("click" , function(){
let searchValue = searchInput.value;
if(searchValue == ""){
alert('First Enter Word');
}else{
getData(searchValue);
}
})