-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (22 loc) · 875 Bytes
/
app.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
var buttonTranslate = document.querySelector("#btn-trans");
var textInput = document.querySelector("#txt-input");
var textOutput = document.querySelector("#txt-output");
var serverURL = "https://api.funtranslations.com/translate/minion.json";
function getTranslationURL(text) {
return serverURL + "?" + "text=" + text
}
function errorHandler(error) {
console.log("Error Occured!", error);
alert(" Sorry! Something went wrong from the server end. Try again after sometime...");
}
function clickHandler() {
var inputText = textInput.value;
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(json => {
var translatedText = json.contents.translated;
textOutput.innerText = translatedText;
})
.catch(errorHandler)
}
buttonTranslate.addEventListener("click", clickHandler);