-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
26 lines (22 loc) · 810 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
var btnTranslate = document.querySelector("#btn-translate");
var txtInput = document.querySelector("#txt-input");
var output = document.querySelector("#output");
var serverURL = "https://api.funtranslations.com/translate/minion.json";
btnTranslate.addEventListener("click", clickHandler)
function updateURL(input) {
return serverURL + "?" + "text=" + input
}
function errorHandler(error) {
console.log(error);
alert("Something went wrong with the server, please try again after some time.");
}
function clickHandler() {
var inputText = txtInput.value;
fetch(updateURL(inputText))
.then(response => response.json())
.then(json => {
var translatedText = json.contents.translated;
output.innerText = translatedText;
})
.catch(errorHandler)
}