-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (18 loc) · 906 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
30
var btnTranslate = document.querySelector("#btn-translate")
var txtInput = document.querySelector("#txt-input")
var outputDiv = document.querySelector("#output")
// var serverUrl = "https://lessonfourapi.tanaypratap.repl.co/translate/yoda.json";
var 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 wrong with the server. Please try some other time");
}
btnTranslate.addEventListener("click", function clickEventHandler() {
// outputDiv.innerText = "banana translation " + inputText.value;
var inputText = txtInput.value;
fetch(getTranslationUrl(inputText))
.then(response => response.json()).then(json => { outputDiv.innerText = json.contents.translated}).catch(errorHandler);
})