-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
28 lines (22 loc) · 821 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 inputTxt = document.querySelector("#txt-input");
var outputDiv = document.querySelector("#output");
function errorHandler(error){
console.log("error Occured");
alert("something went wrong with the server Try again later ........")
}
var serverURL = "https://api.funtranslations.com/translate/valyrian.json";
function getTranslationURL(text){
return serverURL + "?" + "text=" + text;
}
function eventHandler(){
var inputText = inputTxt.value;
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(json => {
var TranslatedText = json.contents.translated;
outputDiv.innerText = TranslatedText;
})
.catch(errorHandler)
}
btnTranslate.addEventListener("click",eventHandler);