-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
34 lines (22 loc) · 822 Bytes
/
main.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
32
33
34
var translateBtn = document.querySelector("#button");
var txtInput = document.querySelector("#txt-area");
var outputDiv = document.querySelector("#output");
var baseURL = "https://api.funtranslations.com/translate/minion.json"
function getTranslationURL(input) {
return baseURL + "?" + "text=" + input
}
function clickHandler() {
var inputText = txtInput.value;
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(result => {
var translatedText = result.contents.translated;
outputDiv.innerText = translatedText;
})
.catch(errorHandler)
};
function errorHandler(error){
console.log(error)
alert("something wrong in the server.Try again sometime")
}
translateBtn.addEventListener("click", clickHandler)