-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
29 lines (24 loc) · 829 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 translateButton = document.querySelector(".translate-button");
var inputText = document.querySelector("#txt-area")
var outputBox = document.querySelector(".outputbox")
var text = inputText.value;
var url = "https://api.funtranslations.com/translate/minion.json"
function constructURL(text){
var url2 = url + "?text=" + text;
return url2;
}
function errorHandler(error){
console.log("error occured ", error);
alert('there was an error, try again after sometime.')
}
function buttonclicked(){
var text = inputText.value;
fetch(constructURL(text))
.then(response=>response.json())
.then(json=> {
var translatedText = json.contents.translated;
outputBox.innerText = translatedText;
})
.catch(errorHandler);
}
translateButton.addEventListener("click", buttonclicked );