-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
31 lines (25 loc) · 914 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
const inputContainer = document.querySelector('.banana-talk-input');
const outputContainer = document.querySelector('.banana-talk-output');
const translationBtn = document.querySelector('.banana-talk-btn');
const API_URL = "https://api.funtranslations.com/translate/minion.json";
console.log(translationBtn);
const getTranslationURL = text => {
return API_URL + "?text=" + text;
}
const setText = text => {
outputContainer.innerText = text;
}
const clickHandler = () => {
const inputText = inputContainer.value;
fetch(getTranslationURL(inputText))
.then(response => response.json())
.then(res => {
const result = res.contents;
const { translated: bananaText } = result;
outputContainer.innerText = bananaText;
})
.catch(err => {
console.log('The API encountered some error!');
})
}
translationBtn.addEventListener('click', clickHandler)