-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
27 lines (21 loc) · 794 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
var textInput = document.querySelector("#input-area");
var outputTextArea = document.querySelector("#output-area");
var btnTranslate = document.querySelector("#btn-translate");
var URL = "https://api.funtranslations.com/translate/minion.json";
function urlBuilder(input){
return URL + "?" + "text=" + input;
}
function errorHandler(error){
console.log("There's been some error over here. Could you maybe try again later?", error);
}
function clickHandler(){
var inputText = textInput.value;
fetch(urlBuilder(inputText))
.then(response => response.json())
.then(json => {
var translatedData = json.contents.translated;
outputTextArea.innerText = translatedData;
})
.catch(errorHandler)
}
btnTranslate.addEventListener("click", clickHandler);