-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (21 loc) · 774 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
28
29
var btntranslate = document.querySelector("#btn-translator");
var txtInput = document.querySelector("#txt-input");
var outputDiv = document.querySelector("#output");
var serverURL = "https://api.funtranslations.com/translate/minion.json";
function getTranslatedURL(text) {
return serverURL + "?" + "text=" + text;
}
function errorHandler(error){
console.log("error occured "+error);
alert("Something gone wrong with server");
}
function clickHandler() {
var inputText = txtInput.value;
fetch(getTranslatedURL(inputText))
.then(response => response.json())
.then(json => {
outputDiv.innerText = json.contents.translated
})
.catch(errorHandler);
};
btntranslate.addEventListener("click", clickHandler);