-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (20 loc) · 800 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
let btnTranslate = document.querySelector("#btn-translate");
let textInput = document.querySelector("#ip-txt");
let outputDiv = document.querySelector("#op-txt");
let serverURL = "https://api.funtranslations.com/translate/minion.json"
function getTranslationURL(text) {
return serverURL + "?" + "text=" + text
}
function errorHandler(error) {
console.log("Error occured", error);
alert("Something is broken, try again after some time")
}
function clickHandler() {
let inputText = textInput.value; //Taking the input
//calling server
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(json => outputDiv.innerText = json.contents.translated)
.catch(errorHandler);
};
btnTranslate.addEventListener("click", clickHandler);