-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (25 loc) · 937 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
29
30
31
var inputTxt = document.querySelector("#input-txt");
var btnTranslate = document.querySelector("#btn-translate");
var outputTxt = document.querySelector("#output-txt");
var serverUrl = "https://api.funtranslations.com/translate/valyrian.json";
function createInputUrl(text){
return serverUrl + "?"+"text=" + text;
}
function errorHandler(error){
console.log(error + " error occured!1!1!1");
alert("Oops sorry!1!1 Something is wrong with the server right now!! Please try again in sometime.");
}
function clickEventHandler(){
//taking input from the user
var inputText = inputTxt.value;
//processing the input
fetch(createInputUrl(inputText))
.then(response => response.json())
.then(json => {
//rendering the output
var translatedText = json.contents.translated;
outputTxt.innerHTML = translatedText;
})
.catch(errorHandler)
}
btnTranslate.addEventListener("click", clickEventHandler);