-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
28 lines (24 loc) · 919 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
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(input){
return serverUrl+ "?" + "text=" + input
}
function errorHandler(error){
console.log("error ",error);
alert("something wrong with the server! try again");
}
function clickHandler(){
// outputdiv.innerText = "ajsjsjsjsjsjsj "+txtInput.value;
var inputTxt = txtInput.value;
fetch(getTranslationUrl(inputTxt))
.then(respone => respone.json())
.then(json => {
var translatedText = json.contents.translated;
outputdiv.innerText = translatedText;
})
.catch(errorHandler)
};
btnTranslate.addEventListener("click", clickHandler);