-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (44 loc) · 1.6 KB
/
Copy pathscript.js
File metadata and controls
55 lines (44 loc) · 1.6 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
const url = 'https://api.dictionaryapi.dev/api/v2/entries/en/';
const output = document.getElementById('output');
const sound = document.getElementById('audio');
const btn = document.getElementById('Search');
btn.addEventListener('click', () => {
let inputWord = document.getElementById('input-word').value;
fetch(`${url}${inputWord}`)
.then((res) => res.json())
.then((data) => {
console.log(data);
output.innerHTML = `<div class="word">
<h3>${inputWord}</h3>
<button onClick="playSound()"><i class="ri-volume-up-fill"></i></button>
</div>
<div class="details">
<p>${data[0].meanings[0].partOfSpeech}</p>
<p>/${data[0].phonetic}/</p>
</div>
<p id="word-meaning">
${data[0].meanings[0].definitions[0].definition}
</p>
<p class="word-example">
${data[0].meanings[0].definitions[0].example || ""}
</p>`;
sound.setAttribute("src", `${data[0].phonetics[0].audio}`);
// console.log(sound);
})
.catch(() => {
output.innerHTML = `<h3 class="error">Couldn't Find the Word</h3>`;
});
});
function playSound() {
sound.play();
}
document.getElementById('contact-link').addEventListener('click', function(event) {
event.preventDefault();
window.location.href = 'mailto:yogesh.jha0704@gmail.com';
});
document.addEventListener('keypress', (event)=>{
let keyCode = event.keyCode ? event.keyCode : event.which;
if(keyCode === 13) {
btn.click();
}
});