-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (23 loc) · 890 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 textInput = document.querySelector('.text-input');
var sectionOutput = document.querySelector('.section-output');
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("API provides only 10 translates in 1 hr");
}
function clickEventHandler(){
var inputText = textInput.value; //taking input
//calling server for processing
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(json => {
var translatedText = json.contents.translated;
sectionOutput.innerText = translatedText; //output
})
.catch(errorHandler)
};
btnTranslate.addEventListener("click", clickEventHandler);