-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (33 loc) · 1.32 KB
/
app.js
File metadata and controls
38 lines (33 loc) · 1.32 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
const selectCountry = document.querySelectorAll("select");
let btn = document.querySelector("button");
let fromText = document.querySelector(".from_text");
let toText = document.querySelector(".to_text");
let textarea = document.querySelectorAll("to_text");
for (let select of selectCountry) {
for (country in countries) {
let newOption = document.createElement("option");
newOption.innerText = countries[country];
newOption.value = country;
if (select.name === "from" && country === "en-GB") {
newOption.selected = "selected";
} else if (select.name === "to" && country === "es-ES") {
newOption.selected = "selected";
}
select.append(newOption);
}
}
btn.addEventListener("click", async () => {
if (fromText.value) {
let text = fromText.value;
let translateFrom = selectCountry[0].value;
let translateTo = selectCountry[1].value;
let URL = `https://api.mymemory.translated.net/get?q=${text}!&langpair=${translateFrom}|${translateTo}`;
let response = await fetch(URL);
let data = await response.json();
toText.value = data.responseData.translatedText;
console.log(data.responseData.translatedText);
}
});
document.getElementById("resetBtn").addEventListener("click", () => {
document.querySelector(".from_text").value = "";
});