-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 1.01 KB
/
index.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
const inputWord = document.querySelector("form");
const infoTextEl = document.getElementById("info-text");
const meaningContainerEl = document.getElementById("meaning-container");
const titleEl = document.getElementById("title");
const meaningEl = document.getElementById("meaning");
const audioEl = document.getElementById("audio");
const translateWord = async(word) => {
const url = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;
const response = await fetch(url);
const data = await response.json();
return data[0];
}
const getTheWorld = (event) => {
event.preventDefault();
const word = inputWord.input.value;
translateWord(word)
.then(word => {
meaningEl.textContent = `${word.meanings[0].definitions[0].definition}`;
titleEl.textContent = word.word;
audioEl.setAttribute("src", `${word.phonetics[1].audio}`);
})
.catch(error => {
console.log(error)
})
}
inputWord.addEventListener("submit", getTheWorld);