-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (25 loc) · 1 KB
/
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
31
32
33
var buttonTranslate = document.querySelector("#btn-translate");
var textInput = 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 (input){
return serverURL + "?" + "text=" + input;
}
function errorHandler(error){
console.log("Error occured", error)
alert("something went wrong with server. Try again after some time!! Sorry for the inconvenience caused")
}
function clickHandler() {
// outputDiv.innerText = "jfbgfufgfuf" + textInput.value;
var inputText = textInput.value;
//calling server for processing
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(json => {
var translateTxt = json.contents.translated
outputDiv.innerText = translateTxt;
})
.catch(errorHandle)
};
buttonTranslate.addEventListener("click", clickHandler);