-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
28 lines (21 loc) · 791 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("#button-translate");
var txtInput = document.querySelector("#text-input");
var txtOutput = document.querySelector("#text-output");
var serverURL = "https://api.funtranslations.com/translate/vulcan.json";
function generateURL(inputText){
return serverURL + "?" + "text=" + inputText;
}
function errorHandler(error){
alert("Something went wrong! Try again later.")
}
function clickHandler(){
var inputText = txtInput.value;
fetch(generateURL(inputText))
.then(response => response.json())
.then(json => {
var translatedText = json.contents.translated;
txtOutput.innerText = translatedText;
})
.catch(errorHandler)
};
btnTranslate.addEventListener("click", clickHandler);