-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
25 lines (19 loc) · 893 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
var btnTranslate = document.querySelector("#translate-button");
var txtInput = document.querySelector("#translate-input");
var outputDiv = document.querySelector("#translate-output");
var serverURL = "https://api.funtranslations.com/translate/navi.json";
function getTranslationURL(input) {
return serverURL + "?" + "text=" + input;
}
function clickHandler() {
var inputText = txtInput.value; // taking input from user
// calling server for processing, for details go to session 4 javascript in browser -> time 2:34:00
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(json => {
var translatedText = json.contents.translated;
outputDiv.innerHTML = translatedText; // output
})
.catch(() => alert("Something wrong with server: try again after some time!"))
}
btnTranslate.addEventListener("click", clickHandler);