-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
28 lines (22 loc) · 871 Bytes
/
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
var btnTranslate = document.querySelector("#btn-translate");
var inputTxt = document.querySelector("#inputText");
var outputText = document.querySelector("#outputText");
var serverUrl = "https://api.funtranslations.com/translate/minion.json";
function getTranslationURl(text) {
return serverUrl + "?" + "text=" + text;
}
function errorHandler() {
console.log("Error Orccured", error);
alert("SomeThing Went Wrong Please Try Again Later");
}
btnTranslate.addEventListener("click", function eventhandler() {
var inputTxt = inputText.value;
fetch(getTranslationURl(inputTxt))
.then((response) => response.json())
.then((json) => {
var translatedText = json.contents.translated;
outputText.innerText = translatedText;
})
.catch(errorHandler);
});
btnTranslate = addEventListener("click", btnTranslate);