-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
29 lines (20 loc) · 872 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 buttontranslate = document.querySelector("#btn-translate");
var textArea = 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 is wrong with the server! try again after some time");
}
function clickedEventHandler(){
var inputText = textArea.value;
fetch(getTranslationURl(inputText))
.then(response => response.json())
.then(json => outputDiv.innerText=json.contents.translated)
.catch(errorHandler);
};
buttontranslate.addEventListener("click", clickedEventHandler);