-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
33 lines (23 loc) · 835 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
29
30
31
32
var btnTranslate = document.querySelector("#btn-translate")
var textInput=document.querySelector("textarea")
var textOutput=document.querySelector("#output")
// var serverUrl = "https://lessonfourapi.tanaypratap.repl.co/translate/yoda.json"
var serverUrl = "https://api.funtranslations.com/translate/minion.json"
function getTranslateUrl(text){
return serverUrl+"?text="+text
}
function errorHandler(error){
console.log("Error occured : ",error)
alert("Something wrong with the server, try after sometime")
}
function eventHandler(){
var text= textInput.value
var url= getTranslateUrl(text)
fetch(url)
.then(response => response.json())
.then(json => {
textOutput.innerText=json.contents.translated
})
.catch(errorHandler)
}
btnTranslate.addEventListener("click",eventHandler)