-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
44 lines (31 loc) · 1.33 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
42
43
44
const url = 'https://api.dictionaryapi.dev/api/v2/entries/en/';
const search_Btn = document.getElementById('search-btn')
search_Btn.addEventListener('click', function () {
const word = document.getElementById('inp-word').value;
fetch(`${url}${word}`)
.then((response) => response.json())
.then((data) => {
console.log(data);
result.innerHTML = `
<div class="word">
<h3>${word}</h3>
</div>
<div class="details">
<p>${data[0].meanings[0].partOfSpeech}</p>
</div>
<p class="word-meaning">
${data[0].meanings[0].definitions[0].definition}
</p>
<p class="word-example">
${data[0].meanings[0].definitions[0].example || ""}
</p>`;
})
.catch(() => {
if (!window.navigator.onLine) {
result.innerHTML = `<h3 class="error">you are offline 📴</h3>`;
}
else{
result.innerHTML = `<h3 class="error">couldn't find the word 😔</h3>`;
}
});
})