-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgroot.js
29 lines (25 loc) · 849 Bytes
/
groot.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
console.log("Hello");
let input=document.querySelector("#INPUT")
let output=document.querySelector("#OUTPUT")
let tran_btn=document.querySelector("#btn-tran")
let url = "https://api.funtranslations.com/translate/groot.json"
function transLate(input){
console.log(url + "?" + "text=" + input)
return url + "?" + "text=" + input
}
function errorHandler(error){
console.log("An error has occured please try again later");
alert("error has occured try again after sometime")
}
function clickHandler(){
let intext=input.value
console.log(intext)
fetch(transLate(intext))
.then(response=>response.json())
.then(json => {
let newText =json.contents.translated;
output.innerText = newText;
})
.catch(errorHandler)
}
tran_btn.addEventListener("click", clickHandler)