-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
25 lines (21 loc) · 781 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
var btnTranslate = document.querySelector("#btn-translate");
var txtInput = document.querySelector("#txt-input");
var txtOutput = document.querySelector("#txt-output");
const serverUrl = " https://api.funtranslations.com/translate/minion.json";
function getTranslatedUrl(text) {
return serverUrl + "?text=" + text;
}
function errorHandler(error) {
console.log("Error occured: ", error);
alert("Try again after sometime!");
}
btnTranslate.addEventListener("click", () => {
var inputText = txtInput.value;
fetch(getTranslatedUrl(inputText))
.then(response => response.json())
.then(json => {
var translatedText = json.contents.translated
txtOutput.innerText = translatedText;
})
.catch(errorHandler)
});