-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (21 loc) · 773 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (21 loc) · 773 Bytes
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
// Creating Variable & Targetting different class using DOM
var input_text = document.querySelector(".text_field");
var translated_text = document.querySelector(".output-result");
var btn = document.querySelector("button");
// Api Url configuration
var url = "https://api.funtranslations.com/translate/minion.json";
function translator(texturl){
return url + "?" + "text=" + texturl;
}
function errorhandle(error){
console.log("Error : " + error);
}
// Click Event
btn.addEventListener("click",function(){
var input = input_text.value;
// translated_text.innerHTML= input;
fetch(translator(input))
.then(response=>response.json())
.then(json => translated_text.innerHTML= json.contents.translated)
.catch(errorhandle);
})